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)
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());
}
}
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";
}
See the wiki for examples and help using Jsonyte.
Discuss with us on Discussions, or raise an issue.
Please read CONTRIBUTING.md for details on how to contribute to this project.
Inspired by the excellent JsonApiSerializer
Jsonyte is released under the MIT License