JsonML (JSON Markup Language) is an application of the JSON (JavaScript Object Notation) data-interchange format. The purpose of JsonML is to provide a compact format for transporting XML-based data via JSON.
A primary use case for this is to send XHTML across the wire to a JSON-aware client (e.g. web browser) and have it easily parse it into DOM elements. JsonML is an ideal format to transmit UI markup via JSON-RPC. It also provides an excellent mechanism for storing UI markup inside of JavaScript.
See how JsonML can help when building UI in Ajax applications. Also, the JsonML filter callback can easily be used to bind behaviors to DOM elements for implementing techniques such as "Progressive Enhancement".
Learn how any arbitrary XML is transformed into JsonML via a simple XSLT.
For an interesting exercise, see how to convert DOM elements to JsonML and back.
A BST system utilizing JsonML has been released which demonstrates the strengths of templating on the client: JsonML+BST.
Following Douglas Crockford's move to make JSON a global object rather than extensions to the JavaScript objects, a compatible JsonML2.js has been produced.
Very little precedent has been set (SPARQL, ATOM) on how to assign the MIME media type of JSON-based formats. Following the the "+xml" suffix convention [RFC3023], the unofficial MIME type for JsonML is: application/jsonml+json
A good JsonML article was recently published on IBM developerWorks. The author walks the reader through some good background on Ajax & JSON before delving into a tutorial of JsonML usage.
To see JsonML+BST in action, play with the live JsonML+BST Example.
Other demonstrations give an idea of the expressive power of JsonML. They also demonstrate the power of the JsonML filter callback for binding behaviors to DOM elements.
Feedback is welcome. If this sounds useful to you, send an email. If you have suggestions which are consistent with the intent here, please feel free to share them.
The following grammar represents how XML-based markup (e.g. XHTML) is encoded into JsonML. As per JSON, whitespace is permitted between tokens.
Implementors MUST serialize the tag-name of the element before attributes or before any element-list. This is because any child text nodes will be siblings to the tag-name of the element. Implementors MUST serialize attributes before any child element as it is more natural to finish populating element attributes before moving onto other elements.
While the process is fairly straight forward to recursively hydrate the element tree from JsonML, there are a number of inconsistencies and quirks to be aware of.
| #5D28D1 | Example text here |
| #AF44EF | 127310656 |
| #AAD034 | © |