Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Object to String

Tags:

json

jquery

How can I take a JSON object and convert it back into the original string format?

Thanks

like image 224
James moore Avatar asked Sep 02 '10 14:09

James moore


People also ask

How do I convert a JSON object to a string?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);

What does JSON Stringify () do?

JSON.stringify() The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

What is JSON Stringify and JSON parse?

parse() is used for parsing data that was received as JSON; it deserializes a JSON string into a JavaScript object. JSON. stringify() on the other hand is used to create a JSON string out of an object or array; it serializes a JavaScript object into a JSON string.

Can we convert JSON string to JSON object?

Using Gson Library It is used to convert JSON String to equivalent JSON Object and JSON Object to JSON String. The following line of code is used to convert JSON String to JSON Object. We can also convert JSON Object to JSON String by using the toJson() method.


2 Answers

You could use an excelent json2.js library: https://github.com/douglascrockford/JSON-js

Check out the JSON.stringify method.

Edit:

It seems like the librabry moved to github repo now: https://github.com/douglascrockford/JSON-js

like image 86
rochal Avatar answered Sep 27 '22 20:09

rochal


Use the stringify method from Douglas Crockford's JSON object:

http://www.json.org/js.html

This will show your object in an alert box:

alert(JSON.stringify(myObject));
like image 22
Silkster Avatar answered Sep 27 '22 22:09

Silkster