JSON 2.0: Libraries and browser support
John is at it again, writing a piece on recent news surrounding JSON.
He links to an updated library by Douglas Crockford, PLAIN TEXT
JAVASCRIPT:
-
-
JSON.stringify({name: “John”, location: “Boston”});
-
// => "{‘name’:'John’,'location’:'Boston’}"
-
JSON.parse(“{‘name’:'John’,'location’:'Boston’}”);
-
// => {name: "John", location: "Boston"}
-
It also turns out that Mozilla implemented this functionality in the browser (time for a wrapper):
JAVASCRIPT:
-
-
var nativeJSON = Components.classes[“@mozilla.org/dom/json;1″]
-
.createInstance(Components.interfaces.nsIJSON);
-
nativeJSON.encode({name: “John”, location: “Boston”});
-
// => "{‘name’:'John’,'location’:'Boston’}"
-
nativeJSON.decode(“{‘name’:'John’,'location’:'Boston’}”);
-
// => {name: "John", location: "Boston"}
-
And in conclusion:
The final, and most important, step is being worked on right now – a way to access native JSON encoding and decoding from web pages. How it’ll be accessible is up to some debate (as having its naming conflict with an existing object would be a really bad thing). Regardless, there should be something within the browser by the time the Firefox 3 betas wrap-up.





