You should use the library json2.js
. It is the basis for the standard JSON.stringify(...)
that some browsers include natively.
You can find the page it originated from here: https://github.com/douglascrockford/JSON-js/blob/master/json2.js
The script automatically makes sure it only adds a JSON.stringify(...)
method if it doesn’t already exist so there is no danger including it in a browser that has it.