JsonPathSerializer 0.2.0
See the version list below for details.
dotnet add package JsonPathSerializer --version 0.2.0
NuGet\Install-Package JsonPathSerializer -Version 0.2.0
<PackageReference Include="JsonPathSerializer" Version="0.2.0" />
<PackageVersion Include="JsonPathSerializer" Version="0.2.0" />
<PackageReference Include="JsonPathSerializer" />
paket add JsonPathSerializer --version 0.2.0
#r "nuget: JsonPathSerializer, 0.2.0"
#:package JsonPathSerializer@0.2.0
#addin nuget:?package=JsonPathSerializer&version=0.2.0
#tool nuget:?package=JsonPathSerializer&version=0.2.0
JsonPathSerializer
Class library that helps putting data incrementally to build a JSON string.
Summary
JsonPathSerializer is a class library that help C# code to build JSON objects incrementally, each time with a JsonPath and a value.
If you're familiar with JSON, you may know that you can use a JsonPath to query a JSON object:
{
"name": [
{
"first": "John",
"last": "Doe"
},
{
"first": "Jane",
"last": "Doe"
}
]
}
If you want to access the value Jane in the above JSON object, you can use the JsonPath $.name[1].first. The JsonPath is a string that describes the path to the value you want to access.
But what if you're given raw data incrementally, and you want to build a structured JSON object from it?
You can use JsonPathSerializer to do that.
This class library can help:
- Automated tests to generate mock data.
- IoT devices to dynamically send back digested data on an interval.
- Web applications to build structured JSON objects from user input.
- And many more!
Requirements
.NET 6.0 or higher.
Newtonsoft.Json 13.0.1 or higher.
Setup
Install from NuGet
dotnet add package JsonPathSerializer
Build from source
git clone
dotnet build
Quick-demo
After downloading the class library, add the following using statement to your code:
using JsonPathSerializer;
Then, try the following code:
Dictionary<string, string> pathToValue = new Dictionary<string, string>()
{
{ "$.say.hello.world", "Hello world!" },
{ "$.say.hello.john", "Hello John!" },
{ "$.say.hi.jane", "Hi jane!" },
{ "$.say.hi.montreal[0]", "Salut Montr�al!" },
{ "$.say.hi.montreal[1]", "Hi Montreal!" },
};
JsonPathManager manager = new JsonPathManager();
foreach (var pair in pathToValue)
{
manager.Add(pair.Key, pair.Value);
}
Console.WriteLine(manager.Build());
Which gives:
{"say":{"hello":{"world":"Hello world!","john":"Hello John!"},"hi":{"jane":"Hi jane!","montreal":["Salut Montr�al!","Hi Montreal!"]}}}
Or:
{
"say": {
"hello": {
"world": "Hello world!",
"john": "Hello John!"
},
"hi": {
"jane": "Hi jane!",
"montreal": [
"Salut Montr�al!",
"Hi Montreal!"
]
}
}
}
Feature Summary
JsonPathSerializer supports a combination of the following JsonPath tokens:
- Property, e.g.
foo.keyor['foo']['key'] - Index, e.g.
foo[1],[-2] - Multiple indexes, e.g.
[1,2],[-2, 3, 1] - Index span, e.g.
[1:3],[-1:],[:2]
For more use case information, please consult the wiki.
Constaints
There are several important known issues and limitations for JsonPathSerializer:
- The library is missing a validation method on type conflict in case the path contains a negative value.
- Supports for wildcard will be implemented in the future.
- Supports for JSON path operators will be gradually implemented.
Release Notes
0.2.0
See v0.2.0 Changelog.
0.1.2
See v0.1.2 Changelog.
0.1.0 (Unstable)
- Initial release.
Future Plans for v0.3.0
Implement a priority mechanism to handle conflicts when adding a value, effectively replacing the
Force()method. There will be 3 levels of priority:Low,Medium, andHigh, withMediumbeing the default equivalent to the currentAdd(),Highbeing equivalent to the currentForce(), andLowto be implemented.Implement an
Append()method that allows user to append a value at the end of the array specified by the path.Implement a validation method on type conflict in case the path contains a negative value.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Newtonsoft.Json (>= 13.0.1)
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 |
|---|---|---|
| 1.0.0 | 172 | 5/30/2024 |
| 0.3.0 | 185 | 1/29/2024 |
| 0.2.0 | 207 | 11/13/2023 |
| 0.1.2 | 133 | 9/26/2023 |
| 0.1.0-beta | 198 | 12/31/2022 |
| 0.1.0-alpha | 188 | 12/31/2022 |