JsonSelector 1.3.0

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

JsonSelector

.NET 10 License: MIT GitHub

A lightweight .NET library for querying JSON payloads using JSONPath expressions. Implements a subset of RFC 9535 (JSONPath: Query Expressions for JSON). No external JSONPath dependencies—built on System.Text.Json only.


Table of Contents


Features

Method Description
Any Check if a selector matches at least one node
FirstString Extract the first matching value as string (numbers use invariant culture)
FirstInt Extract the first matching value as int (supports numeric and string values)

Quick Start

using JsonSelector;

var selector = new JsonSelectorImpl();  // or inject IJsonSelector via DI

string json = """{ "id": 1001, "name": "alpha", "items": [{ "kind": "x", "code": "10" }] }""";

bool exists = selector.Any(json, "$.items[?(@.kind=='x')]");  // true
string? name = selector.FirstString(json, "$.name");           // "alpha"
int? code = selector.FirstInt(json, "$.items[0].code");        // 10

Supported JSONPath Features

  • Root selector$
  • Child selector.name
  • Index selector[0], [1], [-1] (negative index = from end)
  • Bracket notation for filters[?()]
  • Filter expressions@.field, ==, !=, >=, >, <=, <, &&, ||, single-quoted strings, numeric literals
  • isOneOfisOneOf(@.field, 'a','b','c') for multiple-value matching

Path and Selector Examples

Selector Description
$.id Root property
$.data.name Nested property
$.data.myArray[0].myItem Array element by index
$.items[-1].id Last array element (negative index)
$.items[?(@.kind=='x')] Array elements matching filter
$.items[?(@.a=='1' && @.b=='2')] Filter with AND
$.items[?(@.kind=='x' && (@.code=='10' \|\| @.code=='30'))] Filter with OR
$.items[?(@.kind=='x' && isOneOf(@.code, '10','30'))] Filter with isOneOf
$.node1.node2 == 'match' Path value equals (non-array)
$.node1.node2 != 'match' Path value not equals
$.count >= 5 Path value comparison (>=, >, ⇐, <)

Installation

NuGet (GitHub Packages)

dotnet add package JsonSelector

Add the GitHub Packages source to nuget.config if needed:

<packageSources>
  <add key="github" value="https://nuget.pkg.github.com/YOUR_ORG/index.json" />
</packageSources>

Project Reference

<ProjectReference Include="path\to\src\JsonSelector\JsonSelector.csproj" />

Usage

Dependency Injection

using JsonSelector;

// Register with DI
services.AddJsonSelector();

// Inject and use
var selector = serviceProvider.GetRequiredService<IJsonSelector>();

Example with Sample JSON

string json = """
{
  "id": 1001,
  "name": "alpha",
  "items": [
    { "id": "A1", "kind": "x", "code": "10" },
    { "id": "B2", "kind": "y", "code": "20" },
    { "id": "C3", "kind": "x", "code": "30" }
  ]
}
""";

// Check if path exists
bool exists = selector.Any(json, "$.id");

// Check if path value matches (non-array paths)
bool nameMatches = selector.Any(json, "$.name == 'alpha'");
bool idInRange = selector.Any(json, "$.id >= 1000");

// Extract values
string? name = selector.FirstString(json, "$.name");
int? code = selector.FirstInt(json, "$.items[?(@.kind=='x')].code");

// Multiple-value filter (OR)
bool hasMatch = selector.Any(json, "$.items[?(@.kind=='x' && (@.code=='10' || @.code=='30'))]");

// Multiple-value filter (isOneOf)
string? id = selector.FirstString(json, "$.items[?(@.kind=='x' && isOneOf(@.code, '10','20'))].id");

// Array index (first, last, by position)
string? first = selector.FirstString(json, "$.items[0].id");
string? last = selector.FirstString(json, "$.items[-1].id");

Requirements

  • .NET 10.0

License

MIT License — see LICENSE for details.


Repository

Source code: https://github.com/yanis-kr/JsonSelector

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

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.3.0 118 2/25/2026
1.2.1 104 2/23/2026
1.2.0 108 2/23/2026
1.1.1 115 2/20/2026
1.1.0 122 2/20/2026
1.0.0 123 2/17/2026
1.0.0-alpha 110 2/17/2026