Language: EN

csharp-utf8-json

Utf8Json, high-performance JSON converter for C#

Utf8Json is a high-performance JSON serializer and deserializer for .NET, created by developer Yoshifumi Kawai, and released in 2016.

The process of serializing and deserializing JSON files is a frequent need in any modern program. However, it can be costly in terms of performance, especially when dealing with large amounts of data.

That’s why high-speed JSON serialization solutions like Utf8Json were created. It is one of the fastest JSON serializers available in .NET.

It uses the “System.Buffers” method of .NET to avoid GC (garbage collection) overhead that can affect the performance of other JSON serializers. Another reason why Utf8Json is fast is because it uses direct memory access for JSON serialization and deserialization.

In performance tests, Utf8Json is significantly faster than Newtonsoft.Json and System.Text.Json in serializing and deserializing large amounts of data.

In terms of ease of use, Utf8Json is easy to set up and use in .NET. It does not require complicated configurations or customizations, making it an excellent choice for projects looking for a fast and easy-to-use JSON serializer.

How to use Utf8Json

We can easily add the library to a .NET project through the corresponding Nuget package.

Install-Package Utf8Json

Here are some examples of how to use Utf8Json extracted from the library’s documentation

var p = new Person { Age = 99, Name = "foobar" };

// Object -> byte[] (UTF8)
byte[] result = JsonSerializer.Serialize(p);

// byte[] -> Object
var p2 = JsonSerializer.Deserialize<Person>(result);

// Object -> String
var json = JsonSerializer.ToJsonString(p2);

// Write to Stream
JsonSerializer.Serialize(stream, p2);

Utf8Json is Open Source, and all the code and documentation is available in the project’s repository at https://github.com/neuecc/Utf8Json