I'm in the process of learning backbone and I keep seeing these libraries mentioned.
Can't one just use two simple functions on the client,
JSON.stringify
and JSON.parse
for JSON functionality?
Particularly, this tutorial here.
I'm in the process of learning backbone and I keep seeing these libraries mentioned.
Can't one just use two simple functions on the client,
JSON.stringify
and JSON.parse
for JSON functionality?
Particularly, this tutorial here.
Some older browsers don't have these JSON functions built in - so the JSON JavaScript library contains code that poly-fills these older browsers to work just like the newer ones.
The notable exceptions are IE 7 and below.
They're for parsing json, I use it on my music player site: My music player site
Basically it turns them into accessible variables that you can easily use.
Yes you can, provided your environment supports them. But some older browsers do not include the JSON global.
These libraries fill in the gaps.
See Can I Use for explicit details.
The JSON
object is relatively new, and as such isn't supported by older browsers. Those files are intended to implement that functionality for cross-browser support and backwards compatibility.
From http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js:
This file creates a global JSON object containing two methods: stringify and parse.
Difference between json.js and json2.js
I guess parseJSON is obsolete, therefore the new version (json2) doesn't even use it anymore. However if your code uses parseJSON a lot you could just add this piece of code somewhere to make it work again
From the GitHub page (emphasis mine):
json2.js: This file creates a JSON property in the global object, if there isn't already one, setting its value to an object containing a stringify method and a parse method. The parse method uses the eval method to do the parsing, guarding it with several regular expressions to defend against accidental code execution hazards. On current browsers, this file does nothing, preferring the built-in JSON object. There is no reason to use this file unless fate compels you to support IE8, which is something that no one should ever have to do again.