JsonCons.JsonPath 1.0.0-preview.1

This is a prerelease version of JsonCons.JsonPath.
There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonCons.JsonPath --version 1.0.0-preview.1
NuGet\Install-Package JsonCons.JsonPath -Version 1.0.0-preview.1
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="JsonCons.JsonPath" Version="1.0.0-preview.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonCons.JsonPath --version 1.0.0-preview.1
#r "nuget: JsonCons.JsonPath, 1.0.0-preview.1"
#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.
// Install JsonCons.JsonPath as a Cake Addin
#addin nuget:?package=JsonCons.JsonPath&version=1.0.0-preview.1&prerelease

// Install JsonCons.JsonPath as a Cake Tool
#tool nuget:?package=JsonCons.JsonPath&version=1.0.0-preview.1&prerelease

JsonCons.JsonPath

The JsonCons.JsonPath library complements the functionality of the System.Text.Json namespace with an implementation of Stefan Goessner's JsonPath. This implementation has the following features:

  • It is based on a hand-constructed recursive-descent parser that follows a formal grammar described in an ABNF grammar with specification.

  • The basic features are largely compatible with the loose consensus seen in Christoph Burgmer's comparison of 41 JSONPath implementations.

  • Names in the dot notation may be unquoted (no spaces), single-quoted, or double-quoted.

  • Names in the square bracket notation may be single-quoted or double-quoted.

  • Unions of separate JSONPath expressions are allowed, e.g.

    $..[@.firstName,@.address.city]

  • Fiter expressions, e.g. $..book[?(@.price<10)], may omit the enclosing parentheses, like so $..book[?@.price<10].

  • It supports a parent operator ^ for providing access to the parent node, borrowed from JSONPath Plus.

For example, given a system.text.json.JsonDocument obtained as

string jsonString = @"
{
    ""books"":
    [
        {
            ""title"" : ""A Wild Sheep Chase"",
            ""author"" : ""Haruki Murakami"",
            ""price"" : 22.72
        },
        {
            ""title"" : ""The Night Watch"",
            ""author"" : ""Sergei Lukyanenko"",
            ""price"" : 23.58
        },
        {
            ""title"" : ""The Comedians"",
            ""author"" : ""Graham Greene"",
            ""price"" : 21.99
        },
        {
            ""title"" : ""The Night Watch"",
            ""author"" : ""David Atlee Phillips"",
            ""price"" : 260.90
        }
    ]
}";

using JsonDocument doc = JsonDocument.Parse(jsonString);

the JsonCons.JsonPath.JsonSelector class provides functionality to retrieve elements in the JSON document selected according to some criteria,

var selector = JsonSelector.Parse("$.books[?(@.price >= 22 && @.price < 30)]");

IList<JsonElement> elements = selector.Select(doc.RootElement);

The JsonCons.JsonPath library targets .Net Standard 2.1. Reference documentation is available here

Code examples may be found at:

JSONPath examples

Acknowledgements

  • Credit to Stefan Goessner's JsonPath, the original JSONPath.

  • 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 JSONPath filter expressions is greatly influenced by James Saryerwinnie's JMESPath

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 JsonCons.JsonPath:

Package Downloads
Microsoft.CST.ApplicationInspector.RulesEngine The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

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.

Airbyte.Cdk

Package Description

ConfirmSteps.Net

A simple testing suite to confirm the sequence of steps

GitHub repositories (1)

Showing the top 1 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.
Version Downloads Last updated
1.1.0 90,981 8/25/2021
1.0.0 369 8/10/2021
1.0.0-preview.2 198 8/2/2021
1.0.0-preview.1 189 7/29/2021

Initial release