I am using Json.Net to serialize XML into Json . When i write the serialized string to a file it all comes in a single line . How do i get it to actually look like Json with the usual tabs and indentation?
In a composition, an indentation is a blank space between a margin and the beginning of a line of text. The beginning of this paragraph is indented. Standard paragraph indentation is about five spaces or one-quarter to one-half of an inch, depending on which style guide you follow.
SerializeObject Method (Object, Type, JsonSerializerSettings) Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings. Namespace: Newtonsoft.Json.
Specifies the settings on a JsonSerializer object. Newtonsoft.Json. JsonSerializerSettings. Namespace: Newtonsoft.Json.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With