JsonHelper.Net 1.1.5

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

JsonHelper.Net

Nuget License Linter workflow Unit tests workflow

JsonHelper.Net provides typed, null-safe JSONPath querying for Newtonsoft.Json. Eliminate repetitive null checks and type validation when extracting values from JToken objects.

Features

  • Typed selectors — Extract string, bool, int, float, DateTime, Guid, List<T>, or raw JToken directly.
  • Two usage styles — Use JsonHelper.SelectString(json, path) as a static helper or jtoken.SelectString(path) as a fluent extension method.
  • Nullable vs. throwing — Every type provides a nullable method (returns null on missing/wrong type) and an OrThrow variant (throws JsonHelperException for strict validation).
  • Custom date parsing — SelectDate(path, format) parses date strings from arbitrary formats via DateTime.ParseExact.
  • Type-safe JToken access — SelectOrThrow(path, JTokenType.Array) validates the JSON token type at runtime.
  • Built on Newtonsoft.Json 13.0.4 — Targets .NET 7 with nullable reference type annotations.

Quick start

using Newtonsoft.Json.Linq;
using NewtonsoftJsonHelper;

var json = JToken.Parse("""
{
    "name": "Alice",
    "age": 30,
    "active": true,
    "score": 98.5,
    "joined": "2024-01-15T00:00:00",
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
""");

// --- Nullable style (returns null on missing/null/wrong type) ---
string? maybe  = json.SelectString("$.name");          // "Alice"
int?    age    = JsonHelper.SelectInt(json, "$.age");  // 30
bool?   admin  = json.SelectBoolean("$.admin");         // null (missing path)

// --- Throwing style (throws JsonHelperException on failure) ---
string   name  = json.SelectStringOrThrow("$.name");    // "Alice"
float    score = json.SelectFloatOrThrow("$.score");     // 98.5
Guid     id    = json.SelectGuidOrThrow("$.id");         // Guid
DateTime dt    = JsonHelper.SelectDateOrThrow(json, "$.joined"); // DateTime

// --- Without JsonHelper.Net (verbose boilerplate) ---
var nameToken = json.SelectToken("$.name");
var nameValue = nameToken?.ToObject<string>();
if (nameToken == null || nameValue == null)
    throw new Exception("Expected 'name' token");

API Reference

All methods exist in two forms — static JsonHelper and fluent JToken extension methods:

Category Static (JsonHelper) Extension (JTokenExtensions)
String SelectString(json, path) / SelectStringOrThrow(json, path) SelectString(path) / SelectStringOrThrow(path)
Boolean SelectBoolean(json, path) / SelectBooleanOrThrow(json, path) SelectBoolean(path) / SelectBooleanOrThrow(path)
Integer SelectInt(json, path) / SelectIntOrThrow(json, path) SelectInt(path) / SelectIntOrThrow(path)
Float SelectFloat(json, path) / SelectFloatOrThrow(json, path) SelectFloat(path) / SelectFloatOrThrow(path)
DateTime SelectDate(json, path) / SelectDateOrThrow(json, path) SelectDate(path) / SelectDateOrThrow(path)
DateTime (format) SelectDate(json, path, format) / SelectDateOrThrow(json, path, format) SelectDate(path, format) / SelectDateOrThrow(path, format)
Guid SelectGuid(json, path) / SelectGuidOrThrow(json, path) SelectGuid(path) / SelectGuidOrThrow(path)
List<T> SelectList\<T\>(json, path) / SelectListOrThrow\<T\>(json, path) SelectList\<T\>(path) / SelectListOrThrow\<T\>(path)
JToken Select(json, path, params JTokenType[]) / SelectOrThrow(json, path, params JTokenType[]) Select(path, params JTokenType[]) / SelectOrThrow(path, params JTokenType[])
  • Nullable methods return T? and return null when the token is missing, null, or of the wrong type.
  • OrThrow methods return T (non-nullable) and throw JsonHelperException when the token cannot be resolved.

Advanced usage

Date with custom format

var json = JToken.Parse("""{"published": "12/25/2023"}""");

// Parse a string using DateTime.ParseExact
DateTime christmas = json.SelectDateOrThrow("$.published", "MM/dd/yyyy");

List of values

var json = JToken.Parse("""{"ratings": [4.5, 3.8, 5.0, 2.1]}""");
List<float> ratings = json.SelectListOrThrow<float>("$.ratings");

Raw JToken with type validation

var json = JToken.Parse("""{"metadata": {"key": "value"}}""");

// Validates the token is an object, returns the JToken
JToken meta = json.SelectOrThrow("$.metadata", JTokenType.Object);

// Works with multiple acceptable types
JToken field = json.Select("$.metadata", JTokenType.Object, JTokenType.String);

Why JsonHelper.Net?

Without this library, extracting typed values from JToken requires manual null checks and type validation every time:

// Manual checks every time
var token = json.SelectToken("$.some.path");
string? value = null;
if (token != null && token.Type == JTokenType.String)
    value = token.ToObject<string>();
if (value == null)
    throw new Exception("Expected string at $.some.path");

With JsonHelper.Net this becomes a single call:

string value = json.SelectStringOrThrow("$.some.path");

The library handles:

  • JSONPath resolution
  • Null checks (SelectToken can return null)
  • Type validation (checks the JTokenType before converting)
  • Parsing conversions (Guid from string, DateTime from string with format)
  • Clear exception messages on failure

Installation

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.  net10.0 was computed.  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 (3)

Showing the top 3 NuGet packages that depend on JsonHelper.Net:

Package Downloads
Hometrica.Sdk

.NET Sdk for Hometrica.Server

Viklover.Radsel

Radsel CCU API .NET Client

Viklover.Seaweed

SeaweedFS .NET driver

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.5 212 6/22/2026
1.1.4 153 6/22/2026
1.1.3 471 10/25/2025
1.1.2 182 10/25/2025
1.1.1 969 1/21/2025
1.1.0 287 1/21/2025
1.0.4 228 1/6/2025
1.0.3 228 1/6/2025