Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use JSON in older browsers?

In javascript, I want to use JSON.stringify. But some (older) browsers do not recognize JSON as a defined object. Is there a javascript file that I can include that defines JSON, and all it's awesome functionality, for browsers that do not natively support JSON?

I should note that I'm referring to a specifically defined JSON object, rather than the more general concept of javascript object notation.

like image 830
Steve Avatar asked Feb 25 '23 14:02

Steve


1 Answers

Douglas Crockford (the inventor of JSON) provides json2.js, an efficient JSON "parser" that doesn't actually parse JSON; it uses regular expressions to sanitise JSON before passing it to eval, and falls back on native JSON support if the browser has it.

He also provides a more conventional recursive-descent parser and a state-machine-based parser in the same repo.

like image 163
Marcelo Cantos Avatar answered Mar 11 '23 16:03

Marcelo Cantos