A JSON:API serializer/deserializer for System.Text.Json


Keywords
jsonapi, json, api, json:api, serializer, deserializer, serialization, deserialization, dotnet, json-api
License
MIT
Install
Install-Package Jsonyte -Version 0.6.0

Documentation

Jsonyte

Docs NuGet Discussions License

A high-performance library for serializing and deserializing JSON:API documents using System.Text.Json.

Jsonyte aims to be:

  • 🏃 Lightning-fast, as much as 3-5x faster than other JSON:API serializers for .NET
  • 🤝 Simple to setup and easy to use with existing code models
  • 🏗️ Easily integrated with ASP.NET Core
  • ☑️ Fully compliant with the JSON:API v1.0 specification (v1.1 support coming soon)

Usage

Install the package from NuGet with dotnet add package Jsonyte.

var options = new JsonSerializerOptions();
options.AddJsonApi();

var json = JsonSerializer.Serialize(new Article(), options);
var article = JsonSerializer.Deserialize(json, options);

For an ASP.NET Core application, simply add the following to the startup:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddControllers()
            .AddJsonOptions(x => x.JsonSerializerOptions.AddJsonApi());
    }
}

Quick start

Jsonyte will serialize and deserialize plain C# objects to and from the JSON:API format.

For example, the below model will serialize and deserialize the corresponding JSON:API document:

public class Article
{
    public string Id { get; set; } = "1";

    public string Type { get; set; } = "articles";

    public string Title { get; set; } = "JSON:API";
}
{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON:API"
    }
  }
}

Documentation

See the wiki for examples and help using Jsonyte.

Get in touch

Discuss with us on Discussions, or raise an issue.

Discussions

Contributing

Please read CONTRIBUTING.md for details on how to contribute to this project.

Acknowledgements

Inspired by the excellent JsonApiSerializer

License

Jsonyte is released under the MIT License