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" />
<PackageReference Include="JsonHelper.Net" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=JsonHelper.Net&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Newtonsoft.Json helper
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 | Versions 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.
-
net7.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.