QtKaneko.JsonPropertyPath
4.0.1
dotnet add package QtKaneko.JsonPropertyPath --version 4.0.1
NuGet\Install-Package QtKaneko.JsonPropertyPath -Version 4.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="QtKaneko.JsonPropertyPath" Version="4.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QtKaneko.JsonPropertyPath --version 4.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: QtKaneko.JsonPropertyPath, 4.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 QtKaneko.JsonPropertyPath as a Cake Addin #addin nuget:?package=QtKaneko.JsonPropertyPath&version=4.0.1 // Install QtKaneko.JsonPropertyPath as a Cake Tool #tool nuget:?package=QtKaneko.JsonPropertyPath&version=4.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
How to use:
- Install NuGet package.
- Add JsonPropertyPath attribute to properties or fields you want to map with JSONPath:
using QtKaneko.JsonPropertyPath;
// Example JSON:
// {
// "firstName": "John",
// "lastName": "doe",
// "age": 26,
// "address": {
// "streetAddress": "naist street",
// "city": "Nara",
// "postalCode": "630-0192"
// },
// "phoneNumbers": [
// {
// "type": "iPhone",
// "number": "0123-4567-8888"
// },
// {
// "type": "home",
// "number": "0123-4567-8910"
// }
// ]
// }
class Person
{
[JsonPropertyPath("$..streetAddress")]
public string StreetAddress { get; set; } // This property will be mapped to streetAddress from JSON
}
- Add JsonPropertyPathContainingConverter to Converters in your JsonSerializerOptions:
using QtKaneko.JsonPropertyPath;
var options = new JsonSerializerOptions()
{
Converters = {
new JsonPropertyPathContainingConverter()
}
}
Features:
- You can map multiple JSON properties to .NET one:
If JSON property names are the same, they will be merged into array before deserialization:
// Example JSON:
// {
// "firstName": "John",
// "lastName": "doe",
// "age": 26,
// "address": {
// "streetAddress": "naist street",
// "city": "Nara",
// "postalCode": "630-0192"
// },
// "phoneNumbers": [
// {
// "type": "iPhone",
// "number": "0123-4567-8888"
// },
// {
// "type": "home",
// "number": "0123-4567-8910"
// }
// ]
// }
class Person
{
[JsonPropertyPath("$..number")]
public string[] PhoneNumbers { get; set; } // This property will be mapped to all number's from JSON
}
If JSON property names are not the same, they will be merged into object before deserialization:
// Example JSON:
// {
// "glossary": {
// "title": "example glossary",
// "GlossDiv": {
// "title": "S",
// "GlossList": {
// "GlossEntry": {
// "ID": "SGML",
// "SortAs": "SGML",
// "GlossTerm": "Standard Generalized Markup Language",
// "Acronym": "SGML",
// "Abbrev": "ISO 8879:1986",
// "GlossDef": {
// "para": "A meta-markup language, used to create markup languages such as DocBook.",
// "GlossSeeAlso": [
// "GML",
// "XML"
// ]
// },
// "GlossSee": "markup"
// }
// }
// }
// }
// }
class GlossEntry
{
public string ID { get; set; }
public string GlossTerm { get; set; }
}
class Glossary
{
[JsonPropertyPath("$..[ID,GlossTerm]")]
public GlossEntry GlossEntry { get; set; } // This property will be mapped to object created from ID and GlossTerm from JSON
}
This behavior can be changed manually with mergeMode
in JsonPropertyPathAttribute
(JsonPropertyPath
argument) constructor.
You can experiment with JSONPath at https://json-everything.net/json-path/
- And all of this can be used for nested objects!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- JsonPath.Net (>= 0.6.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.0.1 | 235 | 12/10/2023 |