codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Working with JSON in .NET Core 3

Changhui Xu
codeburst
Published in
4 min readOct 28, 2019

With the introduction of ASP.NET Core 3.0 the default JSON serializer has been changed from Newtonsoft.Json to the native System.Text.Json. In this blog post, we will go over some basic usages of JSON serialization and deserialization. The complete solution can be found in this GitHub repository.

A short intro to the fast built-in JSON support

The new built-in JSON support, System.Text.Json, is high-performance, low allocation, and based on Span<byte>. This is all automatic and built in with .NET Core 3.0. But if your project is targeting to .NET Standard or .NET framework (v4.6.1+), then you need to install the System.Text.Json NuGet package, or you can continue to use Json.NET or other popular JSON libraries.

Even though there were many discussions on the JSON library for .NET Core (link), for most .NET users, it is good news to see a native JSON library. Also, there are several benchmark articles (link1, link2, link3, …) which show that the System.Text.Json namespace holds a better performance in most use cases as compared to other JSON libraries. Microsoft has done an excellent job!

The System.Text.Json namespace provides high-performance, low-allocating, and standards-compliant capabilities to process JavaScript Object Notation (JSON), which includes serializing objects to JSON text and deserializing JSON text to objects, with UTF-8 support built-in. It also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM) for random access of the JSON elements within a structured view of the data.

System.Text.Json Namespace from Microsoft Docs

A must-read tutorial by Microsoft Docs

Microsoft Docs has a very good how-to article: How to serialize and deserialize JSON in .NET. Even though it is still under construction, this article has covered a lot of use cases of the System.Text.Json namespace.

In the rest of this blog post, I will show some common use cases of JSON serialization and deserialization.

Using JsonSerializer

Let’s consider a model class MyModel which is defined as follows.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Changhui Xu

Lead Application Developer. MBA. I write blogs about .NET, Angular, JavaScript/TypeScript, Docker, AWS, DDD, and many others.

Responses (3)

Write a response