HyperTextMatters
19 July 2005
 
eval'ing JSON
Post a Comment
One Javascript technology being used alongside of AJAX is JSON: "Javascript Object Notation".  Well-formed JSON amounts to a Javascript associative array literal:
 
{
    org: 'http://www.JSON.org',
    copyright: '(c)2005 JSON.org',
    license: 'http://www.crockford.com/JSON/license.html'
}

Besides strings, a JSON block can contain numbers, and even ordered and associative array literals.  Unfortunately the above block, as contents of a file, would be inaccessible to HTML-embedded Javascript via the script tag's "src" attribute.  The solution recommended on json.org is to use eval(), e.g.:

var myObject = eval('(' + aJSONtext + ')');

This is needlessly slow and insecure.  If instead an identifier, which server-side parsers could simply ignore, were optionally prepended to the object literal block, then JSON could become not just another data exchange format, but a tool for "declarative" client-server web programming.  To that end I propose a new standard, JSON++.
Posted by htmatters at 7:12 AM | Comments (2)
 
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: eval'ing JSON
I've used an AJAX like system base on JSON rather than XML for several months now in a hard-core and very large software application. I've had great experience with it and would encourage people to use JSON rather than XML. I discussed it indirectly in my blog (http://www.journalhome.com/codecraft/8172) but the jist is that from my perspective using XML makes absolutely no sense. I agree that AJAX in general is also limited by the requirement that the user support JavaScript, but for us that was not a concern.

Posted by Kevin Barnes on August 10, 2005 at 6:38 AM

Re: eval'ing JSON
I look forward to your JSON++ proposal.

Posted by thrashor on August 11, 2005 at 12:01 PM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Your comment:

Sorry, no HTML allowed!