Meziantou.Framework.JsonPath
3.0.6
Prefix Reserved
dotnet add package Meziantou.Framework.JsonPath --version 3.0.6
NuGet\Install-Package Meziantou.Framework.JsonPath -Version 3.0.6
<PackageReference Include="Meziantou.Framework.JsonPath" Version="3.0.6" />
<PackageVersion Include="Meziantou.Framework.JsonPath" Version="3.0.6" />
<PackageReference Include="Meziantou.Framework.JsonPath" />
paket add Meziantou.Framework.JsonPath --version 3.0.6
#r "nuget: Meziantou.Framework.JsonPath, 3.0.6"
#:package Meziantou.Framework.JsonPath@3.0.6
#addin nuget:?package=Meziantou.Framework.JsonPath&version=3.0.6
#tool nuget:?package=Meziantou.Framework.JsonPath&version=3.0.6
Meziantou.Framework.JsonPath
An implementation of JSONPath (RFC 9535) for System.Text.Json and custom object models.
Usage
using System.Text.Json.Nodes;
using Meziantou.Framework;
var document = JsonNode.Parse("""{"store":{"book":[{"title":"A"},{"title":"B"}]}}""");
// Parse a JSONPath expression (can be reused)
var path = JsonPath.Parse("$.store.book[*].title");
// Evaluate against a document
var result = path.Evaluate(document);
foreach (var match in result)
{
Console.WriteLine($"{match.Path}: {match.Value}");
// $['store']['book'][0]['title']: A
// $['store']['book'][1]['title']: B
}
Evaluation modes
Evaluate supports two modes:
JsonPathEvaluationMode.Lax(default): path evaluation errors produce no match.JsonPathEvaluationMode.Strict: path evaluation errors throwJsonPathEvaluationException.
var doc = JsonNode.Parse("""{"a": 1}""");
var path = JsonPath.Parse("$.name");
var laxValue = path.EvaluateValue(doc, JsonPathEvaluationMode.Lax); // null
var strictValue = path.EvaluateValue(doc, JsonPathEvaluationMode.Strict); // throws JsonPathEvaluationException
Custom object models
Use JsonPathNavigator<TValue> to evaluate JSONPath expressions against a custom tree without converting it to JsonNode.
var path = JsonPath.Parse("$.items[?@.enabled == true]");
var result = path.Evaluate(root: myRoot, navigator: MyNodeNavigator.Instance);
foreach (var match in result)
{
MyNode? node = match.Value;
Console.WriteLine(match.Path);
}
Navigator implementations expose JSON-like semantics for the custom node type. A null node represents JSON null; a false return value from TryGetPropertyValue or TryGetElement means the member or element is missing. Arrays are zero-based, and object property order follows the navigator's GetProperties enumeration order.
Supported Features
Full RFC 9535 compliance:
- Selectors: name (
.name,['name']), wildcard (*), index ([0],[-1]), slice ([0:3:1]), filter ([?@.price < 10]) - Segments: child and descendant (
..) - Filter expressions: comparisons (
==,!=,<,<=,>,>=), logical operators (&&,||,!), existence tests, parenthesized grouping - Built-in functions:
length(),count(),match(),search(),value() - Normalized paths: canonical path output per RFC 9535 §2.7
Parse rejects every query that is not well-formed and valid, as RFC 9535 §2.1 requires, including queries that
only look valid: !@.a == 1 (negate the comparison with !(@.a == 1)) or @[ 'a' ] == 1 (blank space inside the
brackets makes a query non-singular, so it cannot be compared). The library is tested against the
JSONPath Compliance Test Suite.
Regular expressions
match() and search() take an I-Regexp (RFC 9485) pattern. The
implementation is a checking one (RFC 9485 §3.1): a pattern that is not an I-Regexp, such as one using \d, (?:...),
a lazy quantifier or a backreference, makes the function return false instead of being handed to .NET's own regular
expression engine. Patterns follow the XSD semantics RFC 9485 §4 prescribes: ^ and $ are ordinary characters, .
matches any character except line feed and carriage return, and a character outside the Basic Multilingual Plane
counts as one character. Two cases of the compliance test suite expect ^ and $ to be anchors, following the
non-normative mapping of RFC 9485 §5.3; this library follows §4 instead.
Limits
Parsing
Filter expressions, nested filter selectors, and function arguments may nest up to 64 levels deep. Beyond that,
Parse throws a FormatException and TryParse returns false. The parser is recursive, so this bound is what
keeps a hostile or machine-generated expression from exhausting the stack; 64 matches the default MaxDepth of
System.Text.Json and is far above any practical query.
Evaluation
Descendant segments (..) and deep equality comparisons recurse, so evaluation visits at most 256 levels of
nesting; beyond that it throws JsonPathEvaluationException in both evaluation modes. The limit is higher than the
parser's because documents can legitimately be deeper than expressions: values produced by System.Text.Json's own
parsers cannot exceed their default MaxDepth of 64, so this only affects values built programmatically, parsed
with a raised MaxDepth, or exposed by a custom navigator.
A custom JsonPathNavigator<TValue> should expose an acyclic view of its object model. A cycle — a parent
back-reference, for example — is reported as this same depth error rather than recursing forever.
| Product | Versions 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Meziantou.Framework.JsonPath:
| Package | Downloads |
|---|---|
|
Meziantou.Framework.InlineSnapshotTesting
Enables verification of objects using inline snapshots |
|
|
Meziantou.Framework.TdsServer
A TDS server library for SQL Server protocol connections with query response serialization and ASP.NET Core hosting integration |
|
|
Meziantou.Framework.Language.Json
A Roslyn-style immutable JSON syntax tree: green and red nodes, trivia, diagnostics, annotations, and editing that keeps the text you did not touch. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.6 | 56 | 9/15/2026 |
| 3.0.5 | 187 | 9/13/2026 |
| 3.0.4 | 181 | 9/11/2026 |
| 3.0.3 | 569 | 9/6/2026 |
| 3.0.2 | 1,940 | 8/29/2026 |
| 3.0.1 | 8,007 | 7/8/2026 |
| 3.0.0 | 894 | 7/5/2026 |
| 2.0.4 | 308 | 7/5/2026 |
| 2.0.3 | 4,099 | 6/13/2026 |
| 2.0.2 | 5,220 | 5/23/2026 |
| 2.0.1 | 3,629 | 5/11/2026 |
| 2.0.0 | 853 | 5/6/2026 |
| 1.1.0 | 528 | 5/2/2026 |
| 1.0.2 | 3,738 | 4/25/2026 |
| 1.0.1 | 1,066 | 3/24/2026 |
| 1.0.0 | 138 | 3/24/2026 |