JsonExts.JsonPath
1.0.0
See the version list below for details.
dotnet add package JsonExts.JsonPath --version 1.0.0
NuGet\Install-Package JsonExts.JsonPath -Version 1.0.0
<PackageReference Include="JsonExts.JsonPath" Version="1.0.0" />
paket add JsonExts.JsonPath --version 1.0.0
#r "nuget: JsonExts.JsonPath, 1.0.0"
// Install JsonExts.JsonPath as a Cake Addin #addin nuget:?package=JsonExts.JsonPath&version=1.0.0 // Install JsonExts.JsonPath as a Cake Tool #tool nuget:?package=JsonExts.JsonPath&version=1.0.0
Adds support for mapping properties using JSONPath queries with Newtonsoft.Json.
Usage
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]
.
- Supported on both regular properties and combined with
[DefaultValue]
- Supported on both regular properties and combined with
[JsonPath]
.
- Supported on both regular properties and combined with
[JsonIgnore]
- Only supported on regular properties, not supported combined with
[JsonPath]
.
- Only supported on regular properties, not supported combined with
[JsonProperty]
features supported when combined with[JsonPath]
:-
ItemConverterType
-
NullValueHandling
-
DefaultValueHandling
-
NamingStrategyType
-
MissingMemberHandling
-
ReferenceLoopHandling
-
ObjectCreationHandling
-
TypeNameHandling
-
Required
-
Product | Versions 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. |
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- Newtonsoft.Json (>= 9.0.1)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 9.0.1)
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.