JsonExts.JsonPath 1.0.1

dotnet add package JsonExts.JsonPath --version 1.0.1                
NuGet\Install-Package JsonExts.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="JsonExts.JsonPath" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonExts.JsonPath --version 1.0.1                
#r "nuget: JsonExts.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 JsonExts.JsonPath as a Cake Addin
#addin nuget:?package=JsonExts.JsonPath&version=1.0.1

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

Add [JsonPath(string)] to properties of your model and add [JsonConverter(typeof(JsonPathObjectConverter))] to your model.

Here's an example model:

[JsonConverter(typeof(JsonPathObjectConverter))]
public class Book
{
    [JsonPath("price")]
    public double Price { get; set; }

    [JsonPath("info.author")]
    public string Author { get; set; }

    [JsonPath("info.related[0].title")]
    public string FirstRelatedTitle { get; set; }

    [JsonPath("info.related[*].title")]
    public List<string> RelatedTitles { get; set; }
}

Example JSON being deserialized:

{
    "price": 10.0,
    "info": {
        "title": "Leviathan Wakes",
        "author": "James S. A. Corey",
        "related": [
            { "title": "Caliban's War" },
            { "title": "Abaddon's Gate" },
            { "title": "Cibola Burn" },
            { "title": "Nemesis Games" },
            { "title": "Babylon's Ashes" },
            { "title": "Persepolis Rising" },
            { "title": "Tiamat's Wrath" }
        ]
    }
}

Deserialize the JSON to your model like normal using JsonConvert.DeserializeObject() or a JsonSerializer.

var book = JsonConvert.DeserializeObject<Book>(json);

Alternatively you can leave out the [JsonConverter] attribute on the model and instead specify it when deserializing (or on JsonSerializerSettings).

public class Book 
{
    ...
}

// Add JsonPathObjectConverter to the collection of converters used
var book = JsonConvert.DeserializeObject<Book>(json, new JsonPathObjectConverter())

Serializing book back to JSON again will then result in this:

{
    "price": 10.0,
    "author": "James S. A. Corey",
    "firstRelatedTitle": "Caliban's War",
    "relatedTitles": [
        "Caliban's War", 
        "Abaddon's Gate", 
        "Cibola Burn", 
        "Nemesis Games", 
        "Babylon's Ashes", 
        "Persepolis Rising", 
        "Tiamat's Wrath"
    ]
}

Supported Features

  • [JsonConverter]

    • Supported on both regular properties and combined with [JsonPath].
  • [DefaultValue]

    • Supported on both regular properties and combined with [JsonPath].
  • [JsonIgnore]

    • Only supported on regular properties, not supported combined with [JsonPath].
  • [JsonProperty] features supported when combined with [JsonPath]:

    • ItemConverterType
    • NullValueHandling
    • DefaultValueHandling
    • NamingStrategyType
    • MissingMemberHandling
    • ReferenceLoopHandling
    • ObjectCreationHandling
    • TypeNameHandling
    • Required
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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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 (2)

Showing the top 2 NuGet packages that depend on JsonExts.JsonPath:

Package Downloads
ErgastApiClient

A client for querying the Ergast Developer API (http://ergast.com/mrd/)

Magento.RestClient.Data

Client for the Magento 2.x REST api.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 5,120 4/14/2020
1.0.0 647 7/16/2019

Fixed issue with non-value type properties when path or parts of path was missing