Search This Blog

Tuesday, October 16, 2007

Bridging XML, E4X and JSON

Efforts have been underway recently to develop a schema language for
JSON, analogous to the XML Schema Definition Language (XSD) or RelaxNG
languages in the XML arena. Similarly, a JSON transformation language
is being proposed and bandied about in various AJAX circles as web2
developers attempt to take the best of what XML has to offer and recast
it from the angle-bracket modality to the braced modality... The [JSON]
notation is short, sweet, easy to code and is consistent with normal
JavaScript practices. This simplicity in both declaring and working
with JavaScript (and by extension with JSON) raises significant
questions about whether in fact JSON may in fact be better in this
role of web communication than XML. Admittedly, JSON does have some
limitations. One of the most compelling is the fact that JSON has no
intrinsic concept of namespace. Namespaces are not universally loved
in the XML world, but as people work with an ever larger gamut of XML,
the advantages of namespaces usually become apparent quickly. What this
means in practice is that while it is possible to use lexical namespace
constructs, in JSON, they are only coding conventions -- there is no
intrinsic capability within JavaScript for differentiating on namespaces.
Another problem faced by JSON is what I call the ABA dilemma. A
JavaScript object, like any hash or associate array system, can
effectively store only one 'name' at any given level of object. However,
it can (and indeed should) be argued that the principle role of JSON
is to act as a lightweight object transport envelope, not a document
one, and the ABA problem usually occurs very seldom in object
representations. I've deliberately held off discussing EcmaScript
for XML (e4x) here, because, at least for Mozilla Firefox and Adobe
Flash, e4x readily addresses all of the same issues that JSON does...
I'd like to push a proposal to both the XML and AJAX communities,
something that I think needs to be taken up by the W3C, the OpenAJAX
alliance and JSON.org especially. Establish a set of conventions
within JSON that most readily facilitate JSON being used in an XML
context. These conventions should be syntactical, things that can be
done with hash key naming conventions that can be picked up by a
JSON/XML bridge to transform between the two formats. More Information See also James Clark on XML and JSON: Click Here

No comments: