[javascript] How to convert JSON to string?

Possible Duplicate:
Convert JS object to JSON string

I have a JSON object in JS, and I would like to convert it to string. Is it a function for this?

Thanks in advance,

This question is related to javascript json

The answer is


JSON.stringify()

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.


You can use the JSON stringify method.

JSON.stringify({x: 5, y: 6}); // '{"x":5,"y":6}' or '{"y":6,"x":5}'

There is pretty good support for this across the board when it comes to browsers, as shown on http://caniuse.com/#search=JSON. You will note, however, that versions of IE earlier than 8 do not support this functionality natively.

If you wish to cater to those users as well you will need a shim. Douglas Crockford has provided his own JSON Parser on github.


Try to Use JSON.stringify

Regards