How to serialize a JObject without formatting?

I have a JObject (I use Json.Net) that I built with LINQ to JSON (also provided by the same library). When I call the ToString() method on a JObject , it outputs the results in JSON format.

How to set formatting to "none"?

+43
json serialization
Feb 20 '09 at 18:15
source share
2 answers

Call JObject ToString(Formatting.None) method.

Alternatively, if you pass the object to the JsonConvert.SerializeObject method, it will return JSON without formatting.

Documentation: Writing JSON Text Using JToken.ToString

+83
Feb 21 '09 at 3:27
source share

You can also do the following:

 string json = myJObject.ToString(Newtonsoft.Json.Formatting.None); 
+24
Jun 23 '10 at 13:01
source share



All Articles