Quoth Crockford (http://www.json.org/js.html):
To convert a JSON text into an object,
you can use the eval() function.
eval() invokes the JavaScript
compiler. Since JSON is a proper
subset of JavaScript, the compiler
will correctly parse the text and
produce an object structure. The text
must be wrapped in parens to avoid
tripping on an ambiguity in
JavaScript's syntax.
var myObject = eval('(' + myJSONtext +
')');
The eval function is very fast.
However, it can compile and execute
any JavaScript program, so there can
be security issues. The use of eval is
indicated when the source is trusted
and competent. It is much safer to use
a JSON parser. ...
To defend against this, a JSON parser
should be used. A JSON parser will
recognize only JSON text, rejecting
all scripts. In browsers that provide
native JSON support, JSON parsers are
also much faster than eval. It is
expected that native JSON support will
be included in the next ECMAScript
standard.
var myObject = JSON.parse(myJSONtext,
reviver);
And then he develops the JSON prototype in the rest of the article.
The versions of Gecko used in Firefox 3 and 3.5 support JSON natively (https://developer.mozilla.org/En/JSON), which may be useful if your project is limited to a recent Gecko-based application.
As pointed out below, the interesting part about the text generator (not parser) is at https://github.com/douglascrockford/JSON-js/blob/master/json2.js and introduced with
A JSON stringifier goes in the opposite direction, converting JavaScript data structures into JSON text. JSON does not support cyclic data structures, so be careful to not give cyclical structures to the JSON stringifier.
var myJSONText = JSON.stringify(myObject, replacer);
Cyclic data structures and objects that aren't usefully serialized are obviously the only big caveats there.