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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Extensions.JsonElements" Version="4.0.78" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Extensions.JsonElements" Version="4.0.78" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Extensions.JsonElements" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Extensions.JsonElements --version 4.0.78
                    
#r "nuget: Soenneker.Extensions.JsonElements, 4.0.78"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Extensions.JsonElements@4.0.78
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Extensions.JsonElements&version=4.0.78
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Extensions.JsonElements&version=4.0.78
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 the Int32 range.
  • ToBool() accepts JSON true/false or a case-insensitive Boolean string.
  • ToGuid() accepts a JSON string that Guid can parse.
  • ToDateTime() and ToDateTimeOffset() accept JSON strings, preferring the System.Text.Json ISO 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

Preserve JSON number precision