Skip to content

A System.Text.Json serializer and deserializer for the JSON:API specification.

License

Notifications You must be signed in to change notification settings

jsonyte/jsonyte

Repository files navigation

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"
    }
  }
}

You can also specify your resource type using attributes:

[JsonApiResource("articles")]
public class Article
{
    public string Id { get; set; } = "1";

    public string Title { get; set; } = "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

About

A System.Text.Json serializer and deserializer for the JSON:API specification.

Topics

Resources

License

Stars

Watchers

Forks

Languages