Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

New Format Options of System.Text.Json with .NET 9

New Format Options of System.Text.Json with .NET 9
March 10, 2025 2 min read BEN ABT
Csharp .NET

With .NET 9, Microsoft has added new options to the System.Text.Json library to format the output of JSON objects - features that, in my opinion, should have been available with day 1.

Default Output

Given is the following code that creates a Person object and serializes it with the default options.

C#
 1using System;
 2using System.Text.Json;
 3					
 4public class Program
 5{
 6   public static void Main()
 7   {
 8      Person person = new("Bruce Wayne", new(1915, 4, 7));
 9   
10      string jsonString = JsonSerializer.Serialize(person);
11   
12      Console.WriteLine(jsonString);
13   }
14
15   public sealed record class Person(string Name, DateOnly Birthday);
16}

The output will be:

JSON
{"Name":"Bruce Wayne","Birthday":"1915-04-07"}

This output is very efficient; no additional line breaks or indentations are used to improve readability - but it is just that: very efficient but difficult for humans to read.

Intended Output

From .NET 3.0 and upwards, we have the JsonSerializerOptions class, with which we can specify options; for example, the WriteIndented option, which formats the output.

C#
1JsonSerializerOptions options = new () { WriteIndented = true };
2string jsonString = JsonSerializer.Serialize(person, options);
JSON
1{
2 "Name": "Bruce Wayne",
3 "Birthday": "1915-04-07"
4}

This gives us an output that is easier for people to read.

Defaults

But which output formats are actually the right ones for the respective situation?

With .NET 9, the .NET team has now significantly improved and simplified the output. There is now the option JsonSerializerDefaults.Web with which the developer no longer has to worry about which formats are common - there are now predefined standards.

C#
1JsonSerializerOptions options = new(JsonSerializerDefaults.Web);
2string jsonString = JsonSerializer.Serialize(person, options);

The current implementation of JsonSerializerDefaults.Web is the only one of the enum apart from General; and this is again optimized for web output.

JSON
{"Name":"Bruce Wayne","Birthday":"1915-04-07"}

So if you need an output for the web, you can now simply use the option JsonSerializerDefaults.Web and get an output that is optimized for the web. You still have to take care of the more human-readable output yourself.

C#
1JsonSerializerOptions options = new () { WriteIndented = true };
2string jsonString = JsonSerializer.Serialize(person, options);

However, I assume that we will see more entries in the JsonSerializerDefaults enum in the future, which will provide further standard output formats and thus make it easier for the developer to choose the right output - and to further standardize the output.

Related articles

Production Rate Limiting in ASP.NET Core

Nov 3, 2026 - 16 min read

Production Rate Limiting in ASP.NET Core

Most ASP.NET Core rate-limiting examples stop after registering a fixed window. That is enough to demonstrate the middleware, but it is not …

The Big Decimal Bugfix with .NET 11

Nov 2, 2026 - 11 min read

The Big Decimal Bugfix with .NET 11

For more than two decades, (decimal)1.23 returned 1.23m. It looked correct, it passed every test and it was a polite lie.

Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Oct 27, 2026 - 10 min read

Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Distroless, Chiseled and Alpine are often compared as three equivalent Linux distributions. They are not. Alpine is a distribution built …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Production Rate Limiting in ASP.NET Core

Production Rate Limiting in ASP.NET Core

Nov 3, 2026
The Big Decimal Bugfix with .NET 11

The Big Decimal Bugfix with .NET 11

Nov 2, 2026
Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Oct 27, 2026
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026

Tags

.NET (195) Csharp (99) ASP.NET Core (49) Azure (41) DevOps (17) Docker (15) Microsoft (14) EF Core (11) Microsoft MVP (11) Security (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Synology (9) .NET 11 (8) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact