Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serialize a JObject without the formatting?

People also ask

Is JSON serialize format?

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object). If you serialize this result it will generate a text with the structure and the record returned.

What does JsonConvert SerializeObject do?

SerializeObject Method. Serializes the specified object to a JSON string. Serializes the specified object to a JSON string using formatting.

What is JObject parse in C#?

JObject class has parse method; it parses the JSON string and converts it into a Key-value dictionary object. In the following example, I have used “JObject. Parse” method and retrieved data using key.

Does JSON serialize data?

Serialization is the process of encoding the from naive data type to JSON format. The Python module json converts a Python dictionary object into JSON object, and list and tuple are converted into JSON array, and int and float converted as JSON number, None converted as JSON null.


Call JObject's ToString(Formatting.None) method.

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

Documentation: Write JSON text with JToken.ToString


You can also do the following;

string json = myJObject.ToString(Newtonsoft.Json.Formatting.None);

you can use JsonConvert.SerializeObject()

JsonConvert.SerializeObject(myObject) // myObject is returned by JObject.Parse() method

JsonConvert.SerializeObject()

JObject.Parse()