json

Member-only story

Newtonsoft.Json vs System.Text.Json — A Senior Developer’s Perspective

Is It Vritra - SDE I
5 min readDec 4, 2024

After spending over years on building enterprise-scale .NET applications, I’ve learned that choosing the right JSON serialization library can make or break your application’s performance and maintainability.

Well, the well-known package or defaults right now are Newtonsoft.Json and System.Text.Json. I’ll share my experience with both Newtonsoft.Json and System.Text.Json, helping you make an informed decision for your next project!

JSON Handling in .NET

When I started developing with .NET, Newtonsoft.Json (Json.NET) was the de facto standard. It was everywhere — from small projects to large enterprise applications. Microsoft even used it as the default JSON serializer in ASP.NET Web API and ASP.NET Core (until version 3.0*). But with the introduction of System.Text.Json in .NET Core 3.0, everything changed!

In 2023, I was leading a team working on a high-traffic microservices application processing millions of JSON messages daily and we were using Newtonsoft.Json because, well, that’s what we’d always used. right? But we started noticing memory pressure issues during peak loads. This led us to go down the path that eventually resulted in a migration to System.Text.Json

Performance Difference

After using both libraries, let me break down why System.Text.Json often performs better in a way that makes sense for developers at all levels.

The Speed Difference

JSON processing is like moving boxes (data) from a delivery truck (JSON string) into a warehouse (your application). Here’s how each library handles this:

Newtonsoft.Json (The Traditional Approach)

public class Customer
{
public string Name { get; set; }
public string Email { get; set; }
}

string jsonData = @"{
'name': 'John Doe',
'email': 'john@example.com'
}"
;

var customer = JsonConvert.DeserializeObject<Customer>(jsonData);

What happens behind the scenes:

  1. Creates temporary string copies of the data
  2. Allocates memory multiple times during processing

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

Is It Vritra - SDE I
Is It Vritra - SDE I

Written by Is It Vritra - SDE I

Going on tech shits! AI is my pronouns

Responses (8)

Write a response

The best tool isn’t always the fastest one — it’s the one that best fits your project’s needs and your team’s expertise

This is what everyone should know before hoppin into something...well thanks for sharing artice...i see we need t change things many where...

74

Always centralize your JSON serialization configuration!

That's what make your application clean and clear... Needs to focus on this side... Well I am using system.Text from long time

9

For more specific features, you can use other packages based on System.Text.Json.

10