Activate your free membership today | Log-in

Thursday, January 31st, 2008

JSON 2.0: Libraries and browser support

Category: Browsers, JavaScript, JSON, Library

>John is at it again, writing a piece on recent news surrounding JSON.

He links to an updated library by Douglas Crockford,

JAVASCRIPT:
  1.  
  2. JSON.stringify({name: "John", location: "Boston"});
  3. // => "{'name':'John','location':'Boston'}"
  4. JSON.parse("{'name':'John','location':'Boston'}");
  5. // => {name: "John", location: "Boston"}
  6.  

It also turns out that Mozilla implemented this functionality in the browser (time for a wrapper):

JAVASCRIPT:
  1.  
  2. var nativeJSON = Components.classes["@mozilla.org/dom/json;1"]
  3.     .createInstance(Components.interfaces.nsIJSON);
  4. nativeJSON.encode({name: "John", location: "Boston"});
  5. // => "{'name':'John','location':'Boston'}"
  6. nativeJSON.decode("{'name':'John','location':'Boston'}");
  7. // => {name: "John", location: "Boston"}
  8.  

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.

Related Content:

  • Notable Python language update on view
    Google's interest in Python is just one reason this language continues to gain attention. If you are looking for a scripting language to do some rapid...
  • JSON (Javascript Object Notation)
    JSON (JS Object Notation) is a text-based, human-readable data interchange format used for representing simple data structures and objects in Web...
  • JSON
    JSON (JS Object Notation) is a text-based, human-readable data interchange format used for representing simple data structures and objects in Web...
  • Javascript Object Notation
    JSON (JS Object Notation) is a text-based, human-readable data interchange format used for representing simple data structures and objects in Web...
  • At The Ajax Experience 2 Continued: Browser competition moves Web applications forward
    The Ajax landscape continues to be a place of many frameworks, but several of these library frameworks seem to have gained ground in terms of general...

Posted by Dion Almaer at 5:00 am
2 Comments

++++-
4.7 rating from 16 votes

2 Comments »

Comments feed TrackBack URI

would be better in security.

Comment by phpcs — January 31, 2008

I’m no Asa Dotzler, heavens forbid no, but I reckon passing a JS object to an XPCOM object and then passing it back would make it slower due to unnecessary conversion overhead. Perhaps a pure JS solution would be quicker. Just my speculation.

Comment by Jordan — January 31, 2008

Leave a comment

You must be logged in to post a comment.