How to set formatting with JavaScriptSerializer when JSON serializing?

Peter17 picture Peter17 · May 4, 2011 · Viewed 22.7k times · Source

I am using JavaScriptSerializer for serializing objects to the file to the JSON format. But the result file has no readable formatting. How can I allow formating to get a readable file?

Answer

xelibrion picture xelibrion · May 4, 2011

You could use JSON.NET serializer, it supports JSON formatting

string body = JsonConvert.SerializeObject(message, Formatting.Indented);

Yon can download this package via NuGet.