![]() |
VOOZH | about |
dotnet add package JsonCons.JsonPath --version 1.1.0
NuGet\Install-Package JsonCons.JsonPath -Version 1.1.0
<PackageReference Include="JsonCons.JsonPath" Version="1.1.0" />
<PackageVersion Include="JsonCons.JsonPath" Version="1.1.0" />Directory.Packages.props
<PackageReference Include="JsonCons.JsonPath" />Project file
paket add JsonCons.JsonPath --version 1.1.0
#r "nuget: JsonCons.JsonPath, 1.1.0"
#:package JsonCons.JsonPath@1.1.0
#addin nuget:?package=JsonCons.JsonPath&version=1.1.0Install as a Cake Addin
#tool nuget:?package=JsonCons.JsonPath&version=1.1.0Install as a Cake Tool
The JsonCons.JsonPath library complements the functionality of the System.Text.Json namespace with an implementation of JSONPath. It targets .Net Standard 2.1.
The JsonCons.JsonPath library provides support for querying JsonDocument/JsonElement instances with code like this:
using System;
using System.Collections.Generic;
using System.Text.Json;
using JsonCons.JsonPath;
public static class Example
{
public static void Main(string[] args)
{
string jsonString = @"
{ ""store"": {
""book"": [
{ ""category"": ""reference"",
""author"": ""Nigel Rees"",
""title"": ""Sayings of the Century"",
""price"": 8.95
},
{ ""category"": ""fiction"",
""author"": ""Evelyn Waugh"",
""title"": ""Sword of Honour"",
""price"": 12.99
},
{ ""category"": ""fiction"",
""author"": ""Herman Melville"",
""title"": ""Moby Dick"",
""isbn"": ""0-553-21311-3"",
""price"": 8.99
},
{ ""category"": ""fiction"",
""author"": ""J. R. R. Tolkien"",
""title"": ""The Lord of the Rings"",
""isbn"": ""0-395-19395-8"",
""price"": 22.99
}
],
""bicycle"": {
""color"": ""red"",
""price"": 19.95
}
}
}
";
using JsonDocument doc = JsonDocument.Parse(jsonString);
IList<JsonElement> results = JsonSelector.Select(doc.RootElement, "$..book[?(@.price >= 5 && @.price < 10)]");
var serializerOptions = new JsonSerializerOptions() {WriteIndented = true};
Console.WriteLine(JsonSerializer.Serialize(results, serializerOptions));
}
}
Output:
[
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
}
]
JSONPath is a loosely standardized syntax for querying JSON. The original JavaScript JSONPath is a creation of Stefan Goessner and is described here. Since the original, there have been many implementations in multiple languages, implementations that differ in significant ways. For an exhaustive comparison of differences, see Christoph Burgmer's JSONPath comparison.
The JsonCons implementation attempts to preseve the essential flavor of JSONPath. Where implementations differ, it generally takes into account the consensus as established in the JSONPath comparison. It supports the familar queries against the store:
| JSONPath | Result |
|---|---|
$.store.book[*].author |
The authors of all books in the store |
$..author |
All authors |
$.store.* |
All things in store, which are some books and a red bicycle. |
$.store..price |
The price of everything in the store. |
$..book[2] |
The third book |
$..book[-1:] |
The last book in order. |
$..book[:2] |
The first two books |
$..book[0,1] |
|
$..book[?(@.isbn)] |
Filter all books with isbn number |
$..book[?(@.price<10)] |
Filter all books cheapier than 10 |
$..* |
All members of JSON structure. |
In addition, JsonCons.JsonPath incorporates some generalizations and tightening of syntax introduced in the more innovative and formally specified implementations.
Unquoted names follow the same rules for the selector and in filter expressions, and forbid characters such as hyphens that cause difficulties in expressions.
Names in the dot notation may be unquoted, single-quoted, or double-quoted.
Names in the square bracket notation may be single-quoted or double-quoted.
Like PaesslerAG/jsonpath/ajson, filter expressions
may omit the parentheses around the expression, as in $..book[?@.price<10].
Unions may have separate JSONPath selectors, e.g.
$..[@.firstName,@.address.city]
A parent selector ^, borrowed from JSONPath Plus,
provides access to the parent node.
Options are provided to exclude results corresponding to duplicate paths, and to sort results by paths.
The JsonCons implementation is described in an ABNF grammar with specification. It explicitly implements a state machine that corresponds to this grammar.
Documentation and examples may be found here:
Credit to Stefan Goessner's JsonPath, the original JSONPath. While not a formal specification, it was enormously influential.
The specification of JsonCons.JsonPath draws heavily on Christoph Burgmer's JSONPath Comparison. Many of the test cases and some of the examples are borrowed from this resource.
The specification of JsonCons.JsonPath filter expressions is greatly influenced by James Saryerwinnie's JMESPath, and largely follows JMSPath with regards to truthiness, comparator syntax and semantics, and function syntax and semantics. In Stefan Goessner's original article, filter expressions were left unspecified, and in their original implementations, they were simply Javascript or PHP.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on JsonCons.JsonPath:
| Package | Downloads |
|---|---|
|
Microsoft.CST.ApplicationInspector.RulesEngine
Microsoft Application Inspector is a software source code analysis tool that helps identify and surface well-known features and other interesting characteristics of source code to aid in determining what the software is or what it does. |
|
|
Kurrent.Surge.Core
Package Description |
|
|
Airbyte.Cdk
Package Description |
|
|
ConfirmSteps.Net
A simple testing suite to confirm the sequence of steps |
|
|
TLio.Json.SystemText
TLio System.Text.Json adapter: INodeAdapter and IItemsFetcher implementations backed by System.Text.Json.Nodes.JsonNode and a JsonPath library. Provides identical transformation behaviour to TLio.Json (Newtonsoft) but using the in-box System.Text.Json stack. |
Showing the top 2 popular GitHub repositories that depend on JsonCons.JsonPath:
| Repository | Stars |
|---|---|
|
microsoft/ApplicationInspector
A source code analyzer built for surfacing features of interest and other characteristics to answer the question 'What's in the code?' quickly using static analysis with a json based rules engine. Ideal for scanning components before use or detecting feature level changes.
|
|
|
corvus-dotnet/Corvus.JsonSchema
Support for Json Schema validation and entity generation
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 430,536 | 8/25/2021 |
| 1.0.0 | 647 | 8/10/2021 |
| 1.0.0-preview.2 | 413 | 8/2/2021 |
| 1.0.0-preview.1 | 394 | 7/29/2021 |
Move from preview to release 1.0.0