BlushingPenguin.JsonPath 1.0.1

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

// Install BlushingPenguin.JsonPath as a Cake Tool
#tool nuget:?package=BlushingPenguin.JsonPath&version=1.0.1

ci.appveyor.com codecov.io

BlushingPenguin.JsonPath

BlushingPenguin.JsonPath is a jsonpath implementation for MongoDB.Bson. It is a port of the jsonpath implementation from Newtonsoft.Json.

Packages

BlushingPenguin.JsonPath can also be installed from nuget.org.

Install with package manager:

Install-Package BlushingPenguin.JsonPath

or with nuget:

nuget install BlushingPenguin.JsonPath

Or with dotnet:

dotnet add package BlushingPenguin.JsonPath

Example usage

using BlushingPenguin.JsonPath;

void Example()
{
var o = JsonDocument.Parse(@"{
""Stores"": [
    ""Lambton Quay"",
    ""Willis Street""
],
""Manufacturers"": [
    {
    ""Name"": ""Acme Co"",
    ""Products"": [
        {
        ""Name"": ""Anvil"",
        ""Price"": 50
        }
    ]
    },
    {
    ""Name"": ""Contoso"",
    ""Products"": [
        {
        ""Name"": ""Elbow Grease"",
        ""Price"": 99.95
        },
        {
        ""Name"": ""Headlight Fluid"",
        ""Price"": 4
        }
    ]
    }
]
}");

string? name = o.SelectToken("Manufacturers[0].Name")?.GetString();
// Acme Co

decimal? productPrice = o.SelectToken("Manufacturers[0].Products[0].Price")?.GetDecimal();
// 50

string? productName = o.SelectToken("Manufacturers[1].Products[0].Name")?.GetString();
// Elbow Grease

Assert.AreEqual("Acme Co", name);
Assert.AreEqual(50m, productPrice);
Assert.AreEqual("Elbow Grease", productName);

IList<string> storeNames = o.SelectToken("Stores")!.Value.EnumerateArray().Select(s => s.GetString()).ToList();
// Lambton Quay
// Willis Street

IList<string?> firstProductNames = o.RootElement.GetProperty("Manufacturers")!.EnumerateArray().Select(
    m => m.SelectToken("Products[1].Name")?.GetString()).ToList();
// null
// Headlight Fluid

decimal totalPrice = o.RootElement.GetProperty("Manufacturers")!.EnumerateArray().Aggregate(
    0M, (sum, m) => sum + m.SelectToken("Products[0].Price")!.Value.GetDecimal());
// 149.95

Local Development

Hacking on BlushingPenguin.JsonPath is easy! To quickly get started clone the repo:

git clone https://github.com/blushingpenguin/BlushingPenguin.JsonPath.git
cd BlushingPenguin.JsonPath

To compile the code and run the tests just open the solution in Visual Studio 2019 Community Edition. To generate a code coverage report run cover.ps1 from the solution directory.

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-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)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BlushingPenguin.JsonPath:

Package Downloads
SimpleIdServer.Vc

Library used to manipulate Verifiable Credential.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on BlushingPenguin.JsonPath:

Repository Stars
simpleidserver/SimpleIdServer
OpenID, OAuth 2.0, SCIM2.0, UMA2.0, FAPI, CIBA & OPENBANKING Framework for ASP.NET Core
Version Downloads Last updated
1.0.6 29,442 1/21/2022
1.0.3 13,474 6/8/2020
1.0.2 645 6/8/2020
1.0.1 646 6/8/2020