How do I get formatted and indented JSON in .NET using C#?

Set the JSON writer Formatting property to Formatting.Indented:

jsonWriter.Formatting = Formatting.Indented;

The JsonConvert.Serialize* methods also have overloads that take a Formatting enum (thanks John Flatness).

Documentation: Serialize an Object

Leave a Comment