Formatting json documents

. I am creating a mongo database management utility. I am using visual studio 2010 and framework 4.0. Now that the documents are displayed, they are not formatted, so they are not clear. I just want to decorate it with recesses and line breaks without serializing it; since I do not work with objects. I just received a document and I want to format them. For this, I tried JsonPrettyPrinter.dll, but it uses the 3.5 framework. I have json.net, but I do not know how to use it for formatting. Please tell me how to do this.

+7
source share
2 answers

If you use JSON.NET, you can use this code to format (pretty-print) a JSON document:

string json = "..."; JToken jt = JToken.Parse(json); string formatted = jt.ToString(Newtonsoft.Json.Formatting.Indented); 
+14
source

If this is an option, Chrome and Firefox have a useful plugin called JSONView that does what you want.

+2
source

All Articles