Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives of JSON.stringify() in JavaScript

Tags:

In JavaScript, what are the alternatives of JSON.stringify() for browsers that do not have native JSON support? Thanks

like image 412
weilin8 Avatar asked Sep 26 '09 03:09

weilin8


People also ask

What we can use instead of JSON Stringify?

You should use the library json2. js . It is the basis for the standard JSON.

What is opposite of JSON Stringify?

stringify() is the opposite of JSON. parse(), which converts JSON into Javascript objects. This article and Udacity's JSON.

Do you need JSON for Stringify?

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.

What is difference between serialize and Stringify?

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.


1 Answers

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.

like image 176
Dan Herbert Avatar answered Nov 14 '22 04:11

Dan Herbert