Dyna Dyna - 4 months ago 63
C# Question

Does ServiceStack.Text offer pretty-printing of JSON?

TL;DR: Is there a built-in way in ServiceStack.Text to produce pretty-printed JSON?

I am using ServiceStack.Text for doing JSON serialization. It works really good so far, but the created JSON (using

) is not formated with whitespaces or newlines (most likely to save space when sending over the network). However, in some circumstances it would be nice to have the JSON formatted for easier human-readability.

.Dump ()
method does some sort of formatting, however does not produce valid JSON (i.e. the surrounding doublequotes are missing).


The T.Dump() and T.PrintDump() extension methods in ServiceStack.Text are just a pretty formatted version of the JSV Format that's created with the TypeSerializer class or T.ToJsv() Extension method. It is only to provide a human friendly dump of data, it's not parseable.

There is no PrettyPrint for JSON, I recommend installing a Pretty JSONView extension for Chrome or Firefox to see pretty JSON or you can paste the JSON in jsonprettyprint.com