Soenneker.Extensions.JsonElements
4.0.78
Prefix Reserved
dotnet add package Soenneker.Extensions.JsonElements --version 4.0.78
NuGet\Install-Package Soenneker.Extensions.JsonElements -Version 4.0.78
<PackageReference Include="Soenneker.Extensions.JsonElements" Version="4.0.78" />
<PackageVersion Include="Soenneker.Extensions.JsonElements" Version="4.0.78" />
<PackageReference Include="Soenneker.Extensions.JsonElements" />
paket add Soenneker.Extensions.JsonElements --version 4.0.78
#r "nuget: Soenneker.Extensions.JsonElements, 4.0.78"
#:package Soenneker.Extensions.JsonElements@4.0.78
#addin nuget:?package=Soenneker.Extensions.JsonElements&version=4.0.78
#tool nuget:?package=Soenneker.Extensions.JsonElements&version=4.0.78
Soenneker.Extensions.JsonElements
Strict and non-throwing primitive conversion, string projection, typed deserialization, and recursive object conversion for JsonElement.
Installation
dotnet add package Soenneker.Extensions.JsonElements
Read primitive values
using Soenneker.Extensions.JsonElements;
using JsonDocument document = JsonDocument.Parse(json);
JsonElement root = document.RootElement;
int count = root.GetProperty("count").ToInt();
bool enabled = root.GetProperty("enabled").ToBool();
Guid id = root.GetProperty("id").ToGuid();
The strict converters accept these JSON forms:
ToInt()accepts a JSON integer or an invariant-culture integer string within theInt32range.ToBool()accepts JSONtrue/falseor a case-insensitive Boolean string.ToGuid()accepts a JSON string thatGuidcan parse.ToDateTime()andToDateTimeOffset()accept JSON strings, preferring theSystem.Text.JsonISO 8601 parser and then invariant round-trip parsing.
An incompatible kind, malformed value, or out-of-range number throws FormatException. Use TryToInt(), TryToBool(), or TryToGuid() when invalid input is expected:
if (root.GetProperty("count").TryToInt(out int count))
{
Process(count);
}
IsNullOrUndefined() distinguishes JSON null/missing-style default elements before conversion.
Convert to text
string text = element.ToStr();
ToStr() returns the decoded value for a JSON string, invariant text for an Int64, lowercase text for a Boolean, and an empty string for null or undefined. Decimal/exponent numbers retain their raw JSON token so precision is not lost. Objects and arrays also return their compact raw JSON.
Deserialize a structured value
OrderDto? order = element.To<OrderDto>();
To<T>() uses JsonSerializerOptions.Web. Null and undefined return default; serialization failures propagate. Prefer the primitive methods above when a complete object deserialization is unnecessary.
Build ordinary .NET collections
object? value = element.JsonElementToObject();
JsonElementToObject() recursively maps objects to Dictionary<string, object?>, arrays to List<object?>, strings to string, Booleans to bool, and null/undefined to null. Numbers become long, then decimal, then double according to the first representation that fits; a number outside all three ranges is preserved as raw JSON text. When an object contains duplicate property names, the last value wins.
All methods read from the existing JsonElement. Keep its owning JsonDocument alive for the duration of the call unless the element was cloned.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Json.OptionsCollection (>= 4.0.1278)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Extensions.JsonElements:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Yaml
A utility library handling useful YAML functionalities |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.78 | 0 | 8/30/2026 |
| 4.0.77 | 0 | 8/30/2026 |
| 4.0.76 | 33 | 8/29/2026 |
| 4.0.75 | 36 | 8/29/2026 |
| 4.0.74 | 3,105 | 8/21/2026 |
| 4.0.73 | 2,649 | 8/18/2026 |
| 4.0.72 | 94 | 8/18/2026 |
| 4.0.71 | 8,460 | 8/7/2026 |
| 4.0.70 | 3,294 | 7/28/2026 |
| 4.0.69 | 609 | 7/28/2026 |
| 4.0.68 | 108 | 7/27/2026 |
| 4.0.67 | 4,721 | 7/18/2026 |
| 4.0.66 | 101 | 7/18/2026 |
| 4.0.65 | 9,716 | 7/3/2026 |
| 4.0.64 | 2,667 | 6/20/2026 |
| 4.0.63 | 1,472 | 6/19/2026 |
| 4.0.62 | 623 | 6/18/2026 |
| 4.0.61 | 8,224 | 6/6/2026 |
| 4.0.60 | 595 | 6/5/2026 |
| 4.0.59 | 115 | 6/5/2026 |
Preserve JSON number precision