In JavaScript, what are the alternatives of JSON.stringify()
for browsers that do not have native JSON support? Thanks
You should use the library json2. js . It is the basis for the standard JSON.
stringify() is the opposite of JSON. parse(), which converts JSON into Javascript objects. This article and Udacity's JSON.
The JSON. stringify() method in Javascript is used to create a JSON string out of it. While developing an application using JavaScript, many times it is needed to serialize the data to strings for storing the data into a database or for sending the data to an API or web server.
stringify() ignores functions/methods when serializing. JSON also can't encode circular references. Most other serialization formats have this limitation as well but since JSON looks like javascript syntax some people assume it can do what javascript object literals can. It can't.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With