How to print beautifully with System.Json?

Using the new System.Json from 4.5 or equivalent System. Json for 4.0 from Nuget , how do you format the output so that it is indented ans, located in a more readable form?

So this is

dynamic jsonObj = new JsonObject(); jsonObj.firstName = "John"; jsonObj.lastName = "Smith"; Debug.WriteLine((string)jsonObj.ToString()); 

Displays this

 {"firstName":"John","lastName":"Smith"} 

When i want this

 { "firstName": "John", "lastName": "Smith" } 
+4
source share
2 answers

For future reference, the System.Json library in .NET 4.5 (only for version 4.5, not Silverlight) has a JsonSaveOptions counter, so you can call ToString(JsonSaveOptions.EnableIndent) for a pretty printed Json.

+7
source

Unlike XML, the built-in library has no parameters.

Mark Rogers has written a preferred, available here:

http://www.markdavidrogers.com/json-pretty-printerbeautifier-library-for-net/

+3
source

Source: https://habr.com/ru/post/1403014/


All Articles