JsonHelper.Net 1.1.1

dotnet add package JsonHelper.Net --version 1.1.1
                    
NuGet\Install-Package JsonHelper.Net -Version 1.1.1
                    
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="JsonHelper.Net" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonHelper.Net" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="JsonHelper.Net" />
                    
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 JsonHelper.Net --version 1.1.1
                    
#r "nuget: JsonHelper.Net, 1.1.1"
                    
#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.
#addin nuget:?package=JsonHelper.Net&version=1.1.1
                    
Install JsonHelper.Net as a Cake Addin
#tool nuget:?package=JsonHelper.Net&version=1.1.1
                    
Install JsonHelper.Net as a Cake Tool

Newtonsoft.Json helper

Nuget License Linter workflow Unit tests workflow

Extension methods for Newtonsoft.Json library.

Now you can select JSON tokens by paths without nullability checks:

var json = JToken.Parse("{\"hello\":\"world\"}");

// Newtonsoft.Json approach
var worldToken = json.SelectToken("$.world");
var worldTokenValue = worldToken?.ToObject<string>();
if (worldToken == null || worldTokenValue == null) {
    throw Exception("Expected 'world' token");
}

// JsonHelper.Net approach
var world = json.SelectStringOrThrow("$.world");

You can also select .NET native types like Guid or DateTime:

// {"guid":"b3f3f9bc-8b7d-4199-971b-6c35152412da","date":"2024-01-05T00:00:00.0000000"}

Guid guid = json.SelectGuid("$.guid")
DateTime date = json.SelectDate("$.date");

// use `SelectGuidOrThrow` or 'SelectDateOrThrow' if expected non-nullable value

If you need to select raw complex JToken objects, the helper provides some useful methods:

// {"dict":{"body":["a","b","c",{"foo":"bar"}]}}

JToken body = json.SelectOrThrow("$.dict.body", JTokenType.Array);

Selecting List<T>:

// {"list":[1, -0.92, 3.47, 4]}
var list = json.SelectListOrThrow<float>("$.list");

Installation

dotnet add package JsonHelper.Net --version 1.1.0

Nuget page is here

Contribution

Pull requests are welcome! I will gladly review any feature suggestions and consider them for inclusion in the library.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 104 3 months ago
1.1.0 85 3 months ago
1.0.4 103 3 months ago
1.0.3 117 3 months ago