Jackson 2.0.0

dotnet add package Jackson --version 2.0.0
                    
NuGet\Install-Package Jackson -Version 2.0.0
                    
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="Jackson" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jackson" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Jackson" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Jackson --version 2.0.0
                    
#r "nuget: Jackson, 2.0.0"
                    
#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.
#:package Jackson@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Jackson&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Jackson&version=2.0.0
                    
Install as a Cake Tool

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:

dotnet add package Jackson

Build a parser to map JSON data to .NET types:

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<Type1>("type", "1")
    .Map<Type2>("type", "2")
    .Or(
        Parser
            .Create(JsonSerializerOptions.Default, "f1", "f2")
            .Map<Type1>("1", "type")
            .Map<Type2>("2", "type")
            .Build()
    )
    .Build();

var node = JsonSerializer.Deserialize<JsonNode>(json);

if (parser.Parse(node) is IEnumerable<object> seq)
{
    foreach (object item in seq)
    {
        Console.WriteLine(item);
    }
}

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 197 1/5/2025
1.0.0 1,028 10/16/2024