JsonML

From Wikipedia, the free encyclopedia

JSON Markup Language
Internet media type application/jsonml+json (unofficial)
Type of format Markup language
Extended from XML and JSON

The JSON Markup Language (JsonML) is a lightweight markup language which is used as a mapping between XML and JSON (JavaScript Object Notation). Using JsonML one may convert an XML document or fragment into a JSON data structure for ease of use within JavaScript environments such as a Web Browser. JsonML allows manipulation of XML data without the need or overhead of an XML parser.

JsonML has greatest applicability in Ajax web applications. It may be used to transport XHTML down to the client where it can be deterministically reconstructed into DOM Elements. Strategies such as progressive enhancement may be employed during construction to bind dynamic behaviors to the otherwise static elements.

[edit] Syntax

JsonML uses JSON Arrays to represent XML elements, JSON Objects to represent attributes, and JSON Strings to represent Text nodes. Conversion from XML to JsonML is fully reversible. XML Namespaces are handled by prepending the element name with the namespace prefix (e.g. <myns:myElement/> becomes ["myns:myElement"]).

<!-- XML representation of a person record -->
<person created="2006-11-11T19:23" modified="2006-12-31T23:59">
    <firstName>Robert</firstName>
    <lastName>Smith</lastName>
    <address type="home">
        <street>12345 Sixth Ave</street>
        <city>Anytown</city>
        <state>CA</state>
        <postalCode>98765-4321</postalCode>
    </address>
</person>

/* JsonML representation of a person record */
["person", {"created":"2006-11-11T19:23", "modified":"2006-12-31T23:59"},
    ["firstName", "Robert"],
    ["lastName", "Smith"],
    ["address", {"type":"home"},
        ["street", "12345 Sixth Ave"],
        ["city", "Anytown"],
        ["state", "CA"],
        ["postalCode", "98765-4321"]
    ]
]