Meziantou.Framework.JsonPath
3.0.0
Prefix Reserved
dotnet add package Meziantou.Framework.JsonPath --version 3.0.0
NuGet\Install-Package Meziantou.Framework.JsonPath -Version 3.0.0
<PackageReference Include="Meziantou.Framework.JsonPath" Version="3.0.0" />
<PackageVersion Include="Meziantou.Framework.JsonPath" Version="3.0.0" />
<PackageReference Include="Meziantou.Framework.JsonPath" />
paket add Meziantou.Framework.JsonPath --version 3.0.0
#r "nuget: Meziantou.Framework.JsonPath, 3.0.0"
#:package Meziantou.Framework.JsonPath@3.0.0
#addin nuget:?package=Meziantou.Framework.JsonPath&version=3.0.0
#tool nuget:?package=Meziantou.Framework.JsonPath&version=3.0.0
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
| 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
Immutable JSON concrete syntax tree with diagnostics, trivia, source locations, and editing helpers. |
GitHub repositories
This package is not used by any popular GitHub repositories.