Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/milandjurdjevic/jackson
A .NET library for JSON parsing built on top of System.Text.Json, offering advanced type discrimination.
https://github.com/milandjurdjevic/jackson
csharp discriminator dotnet fsharp json parser systemtextjson
Last synced: 2 days ago
JSON representation
A .NET library for JSON parsing built on top of System.Text.Json, offering advanced type discrimination.
- Host: GitHub
- URL: https://github.com/milandjurdjevic/jackson
- Owner: milandjurdjevic
- License: mit
- Created: 2024-10-16T00:05:01.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-10-16T01:59:10.000Z (4 months ago)
- Last Synced: 2024-10-18T22:09:21.732Z (4 months ago)
- Topics: csharp, discriminator, dotnet, fsharp, json, parser, systemtextjson
- Language: F#
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jackson
A .NET library for JSON parsing built on top of System.Text.Json, offering advanced type discrimination.
## Motivation
Handling objects with complex discrimination requirements in JSON deserialization can be difficult. While
System.Text.Json supports basic deserialization well, it often requires cumbersome and error-prone custom converters for
more complex logic.This library simplifies the process by providing an easy solution for deserializing JSON data into objects with complex
discrimination needs. By extending System.Text.Json's capabilities, it allows developers to seamlessly deserialize JSON,
even with intricate discrimination requirements.With this library, developers can map JSON data to their object models efficiently, without needing extensive custom
converter implementations. This results in a simpler and more maintainable deserialization process.## Get Started
Install package from NuGet:
```shell
dotnet add package Jackson
```Build a parser to map JSON data to .NET types:
```csharp
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using Jackson;public class Type1;
public class Type2;var json =
"""
[
{ "f1": "type", "f2": "1" },
{ "f1": "type", "f2": "2" },
{ "f1": "1", "f2": "type" },
{ "f1": "2", "f2": "type" },
{ "f1": "dynamic", "f2": [1, 2, 3], "f3": { "f1": "type", "f2": "1" } }
]
""";var parser = Parser
.Create(JsonSerializerOptions.Default, "f1", "f2")
.Map("type", "1")
.Map("type", "2")
.Or(
Parser
.Create(JsonSerializerOptions.Default, "f1", "f2")
.Map("1", "type")
.Map("2", "type")
.Build()
)
.Build();var node = JsonSerializer.Deserialize(json);
if (parser.Parse(node) is IEnumerable seq)
{
foreach (object item in seq)
{
Console.WriteLine(item);
}
}
```## License
This project is licensed under the [MIT License](LICENSE).