Conversion from XML to JsonML is partially reversible. XML Namespaces are handled by prepending the element name with the namespace prefix, e.g., <myns:myElement/> becomes ["myns:myElement"].
JsonML allows any XML document to be represented uniquely as a JSON string. The syntax uses:
A “regular” JSON transformation produces a more compact representation, but loses some of the document structural information, in that it does not define whether a key-value pair is an attribute or a node:
In a JSON user group thread, Douglas Crockford incorrectly used the term "JsonML" to describe two variants: the "array form" and "object form".3 This was a misuse of the term JsonML which has always stood to mean what Crockford referred to as the "array form".4
JsonML can be validated with the following JSON schema:
XML and XSLT (Extensible Stylesheet Language Transformations) can also produce client-side templating, and both allow caching of the template separate from the data. JBST uses JavaScript natively in the template, rather than requiring mixing of different types of control language.
While seemingly used to perform similar tasks, JsonML and innerHTML are quite different. InnerHTML requires all the markup in an exact form, meaning that either the server is rendering the markup, or the programmer is performing expensive string concatenations in JavaScript.
JsonML uses client-side templating through JBST, which means that HTML is converted into a JavaScript template at build time. At run time, the data is supplied and DOM elements are the result. The resulting DOM elements can be inserted or replace an existing element, which innerHTML cannot easily do without creating excess DOM elements. Rebinding only requires requesting additional data, which is smaller than fully expanded markup. As a result, large performance gains are often made, since the markup is requested or cached separately from the data.
For simplicity, innerHTML has been the preferred method for the HTML-Message pattern5 style of Ajax. However, tools like JsonFx6 aim to simplify JsonML and JBST implementation while still providing a full browser-side templating Ajax pattern.7
McKamey, Stephen M. (3 February 2007). "JsonML - Binding Behaviors to DOM Elements". Official website. JsonML.org. Archived from the original on 14 August 2010. Retrieved 7 January 2011. https://web.archive.org/web/20100814050135/http://jsonml.org/Ajax-UI/Binding/ ↩
McKamey, Stephen M. (3 August 2008). "JsonML + Browser-Side Templating (JBST)". Official website. JsonML.org. Retrieved 7 January 2011. http://jsonml.org/bst/ ↩
"Json : Message: Org.json.JSONML.java". Archived from the original on 2012-04-27. Retrieved 2009-02-12. https://web.archive.org/web/20120427021252/http://tech.groups.yahoo.com/group/json/message/1115 ↩
"JsonML (JSON Markup Language)". http://jsonml.org/syntax/ ↩
"HTML Message". About AjaxPatterns.org. AjaxPatterns.org. Archived from the original on 1 July 2012. Retrieved 7 January 2011. https://archive.today/20120701122939/http://ajaxpatterns.org/HTML_Message ↩
"Welcome to JsonFx.NET". JsonFx.NET Official Website. Stephen M. McKamey. Retrieved 7 January 2011. http://jsonfx.net/ ↩
"Browser-Side Templating". AjaxPatterns.org. Archived from the original on 7 July 2012. Retrieved 7 January 2011. https://archive.today/20120707073731/http://ajaxpatterns.org/Browser-Side_Templating ↩