•               
    <html lang="en-US">
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>EXI for JSON (EXI4JSON)</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <style type="text/css">
    code           { font-family: monospace; }
    
    div.constraint,
    div.issue,
    div.note       { margin-left: 2em; }
    div.notice     { margin-left: 2em; font-weight: bold; font-size: larger; color: red }
    
    ol.enumar      { list-style-type: decimal; }
    ol.enumla      { list-style-type: lower-alpha; }
    ol.enumlr      { list-style-type: lower-roman; }
    ol.enumua      { list-style-type: upper-alpha; }
    ol.enumur      { list-style-type: upper-roman; }
    
    
    div.exampleInner pre { margin-left: 1em;
                           margin-top: 0em; margin-bottom: 0em}
    div.exampleOuter {border: 4px double gray;
                      margin: 0em; padding: 0em}
    div.exampleInner { background-color: #d5dee3;
                       border-top-width: 4px;
                       border-top-style: double;
                       border-top-color: #d3d3d3;
                       border-bottom-width: 4px;
                       border-bottom-style: double;
                       border-bottom-color: #d3d3d3;
                       padding: 4px; margin: 0em }
    div.exampleWrapper { margin: 4px }
    div.exampleHeader { font-weight: bold;
                        margin: 4px}
    
      
       tr.silver td { color: silver; font-style: italic }
    
       tr.bold td { font-weight: bold }
       
       td.xml { background-color: black; color: white; font-weight: bold; font-size: 100% }
       .schema-less { background-color: silver; font-style: italic }
       .schema-informed { background-color: gray; }
       
       td.footnote { font-size: 75% }
       
       table.tableBorders tr th,
       table.tableBorders tr td
       {
          border: 1px solid gray;
          padding: 5px;
          /*margin: 5px;*/
       }
    
    </style>
    <link rel="stylesheet" type="text/css" href="https://www.w3.org/StyleSheets/TR/2016/W3C-WG-NOTE.css">
    <link rel="canonical" href="https://www.w3.org/TR/">
    </head>
    <body>
    <div class="head">
    <p>
    <img src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" alt="W3C" height="48" width="72">
    </p>
    
    <h1>
    EXI for JSON (EXI4JSON)</h1>
    
    <h2>
    W3C Working Group Note 26 July 2018</h2>
    <dl>
    <dt>This version:</dt>
    <dd>
    https://www.w3.org/TR/2018/NOTE-exi-for-json-20180726/
    </dd>
    <dt>Latest version:</dt>
    <dd>
                
    https://www.w3.org/TR/exi-for-json/
            
    </dd>
    <dt>Previous version:</dt>
    <dd>
    https://www.w3.org/TR/2016/WD-exi-for-json-20160823/
    </dd>
    <dt>Editors:</dt>
    <dd>Daniel Peintner, Siemens AG</dd>
    <dd>Don Brutzman, Web3D Consortium</dd>
    </dl>
    <p class="copyright">
    Copyright © 2018 W3C<sup>®</sup> (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.</p>
    <hr>
    </div>
    <div>
    
    <h2>
    Abstract</h2>
    <p>The EXI format is a compact representation that
                    simultaneously optimizes performance and the utilization of computational resources.
                    The EXI format was designed to support XML representation. With a relatively small
                    set of transformations it may also be used for JSON, a popular format for exchange
                    of structured data on the Web. </p>
    </div>
    <div>
    
    <h2>
    Status of this Document</h2>
    <p>
                    
    This section describes the status of this document at the time of its
                        publication. Other documents may supersede this document. A list of current W3C
                        publications and the latest revision of this technical report can be found in
                        the W3C technical reports index at https://www.w3.org/TR/.
                
    </p>
    
    <p>This document has been produced by the Efficient Extensible Interchange (EXI) Working Group. The goals of the EXI Format are discussed in the EXI Format document. </p>
    
    <p>Publication as a Working Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.</p>
    
    <p>Please send comments about this document to the [email protected] mailing list (Archives).</p>
    
    <p data-deliverer="38502">This document was produced by a group operating under the W3C Patent Policy.</p>
    
    <p>This document is governed by the 1 February 2018 W3C Process Document.</p>
    </div>
    <nav id="toc">
    
    <h2>
    Table of Contents</h2>
    
    1. <span class="secno">1. </span><span class="content">Introduction</span>
      1. <span class="secno">2. </span><span class="content">Concept</span>
        1. <span class="secno">3. </span><span class="content">Representing JSON data using EXI</span>
          1. <span class="secno">3.1 </span><span class="content">JSON object</span>
            1. <span class="secno">3.1.1 </span><span class="content">Key-name Escaping</span>
          2. <span class="secno">3.2 </span><span class="content">JSON array</span>
            1. <span class="secno">3.3 </span><span class="content">JSON string</span>
              1. <span class="secno">3.4 </span><span class="content">JSON number</span>
                1. <span class="secno">3.5 </span><span class="content">JSON true</span>
                  1. <span class="secno">3.6 </span><span class="content">JSON false</span>
                    1. <span class="secno">3.7 </span><span class="content">JSON null</span>
                    2. <span class="secno">A </span><span class="content">References</span>
                      1. <span class="secno">B </span><span class="content">XML Schema for EXI4JSON</span>
                        1. <span class="secno">C </span><span class="content">Design Decisions</span> (Non-Normative)
                          1. <span class="secno">C.1 </span><span class="content">Selection of other Datatype Representations</span>
                            1. <span class="secno">C.2 </span><span class="content">Character Encoding</span>
                              1. <span class="secno">C.3 </span><span class="content">Selection of EXI options</span>
                                1. <span class="secno">C.3.1 </span><span class="content">EXI Option strict</span>
                                2. <span class="secno">C.3.2 </span><span class="content">EXI Option schemaId</span>
                              2. <span class="secno">C.4 </span><span class="content">Change of Structure</span>
                              3. <span class="secno">D </span><span class="content">Examples</span> (Non-Normative)
                                1. <span class="secno">D.1 </span><span class="content">Example 1</span>
                                  1. <span class="secno">D.2 </span><span class="content">Example 2</span>
                                    1. <span class="secno">D.3 </span><span class="content">Example 3</span>
                                    2. <span class="secno">E </span><span class="content">Schema Mapping</span> (Non-Normative)
                                      1. <span class="secno">E.1 </span><span class="content">JSON object</span>
                                        1. <span class="secno">E.2 </span><span class="content">JSON array</span>
                                          1. <span class="secno">E.3 </span><span class="content">JSON string</span>
                                            1. <span class="secno">E.4 </span><span class="content">JSON number</span>
                                              1. <span class="secno">E.5 </span><span class="content">JSON boolean</span>
                                                1. <span class="secno">E.6 </span><span class="content">JSON null</span>
                                                  1. <span class="secno">E.7 </span><span class="content">JSON enumeration</span>
                                                  2. <span class="secno">F </span><span class="content">Acknowledgements</span> (Non-Normative)
                                                    </nav> <hr> <div class="body"> <div class="div1"> <h2> 1. Introduction</h2> <p>JSON is a popular format for exchange of structured data on the Web and it is specified in [RFC 7159 - The JavaScript Object Notation (JSON) Data Interchange Format] and [ECMA-404 - The JSON Data Interchange Format]. This document describes how the [Efficient XML Interchange (EXI) Format 1.0 (Second Edition)] specification can be used to represent JSON data efficiently in terms of message size and processing. </p> </div> <div class="div1"> <h2> 2. Concept</h2> <p>The EXI for JSON approach is to equivalently convert any well-formed JSON structures to XML event streams (Appendix D Examples shows some examples) that are directly suitable for datatype-aware EXI representation. Lossless round-trip conversion back to the original JSON structures is supported.</p> <p>The proposed XML event stream results in a compact format — the so-called EXI for JSON (or EXI4JSON) document — that can be read and written with little additional software. That said, Appendix B XML Schema for EXI4JSON provides an XML Schema describing the EXI for JSON document. EXI processors use the <cite>schema-informed grammars</cite> that stem from this schema. </p> <p>The <cite>EXI Options</cite> describe the EXI options that may be used for any EXI document. Negotiation of what options need to be supported by an EXI for JSON implementation are handled externally to the document. This specification makes use of the default options with the following modifications: </p> <table class="tableBorders"> <caption>Table 2-1. Predefined EXI4JSON EXI Options</caption> <tbody> <tr> <th>EXI Option</th><th>Description</th><th>Value</th> </tr> <tr> <td><cite>strict</cite></td><td>Strict interpretation of schemas is used to achieve better compactness</td><td>true</td> </tr> <tr> <td><cite>schemaId</cite></td><td>Identify the schema information, if any, used to encode the body</td><td>"exi4json"</td> </tr> </tbody> </table> <p></p> <p>Both EXI Options for strict and schemaId are REQUIRED and cannot be changed. If future versions of EXI for JSON are specified, version identification is reflected in the schemaId value.</p> </div> <div class="div1"> <h2> 3. Representing JSON data using EXI</h2> <p> Any valid JSON data can be converted to equivalent EXI. Similarly, corresponding EXI streams that conform to the rules and schema of this specification can be converted to equivalent JSON. The following subsections specify how JSON data MUST be represented for equivalent round-trip conversion. This approach is not suitable for arbitrary EXI or XML data. </p> <p>Prefixes are used throughout this section to designate certain namespaces. The bindings shown below are assumed, however, any prefixes can be used in practice if they are properly bound to the namespaces. </p> <table class="tableBorders"> <tbody> <tr> <th>Prefix</th><th>Namespace Name</th> </tr> <tr> <td>j</td><td>http://www.w3.org/2015/EXI/json</td> </tr> </tbody> </table> <p>Also, the specification makes use of EXI event terminology and the associated grammar notation (e.g., SE stands for Start Element and EE for End Element) that is fully described in the EXI specification dealing with <cite>EXI Event Types</cite>.</p> <p>A JSON value is an object, array, string, or number, or one of the following three literal names: true false null.</p> <div class="div2"> <h3> 3.1 JSON object </h3> <p>A JSON object is represented as a j:map element which may comprise a set of key/value pairs as it content.</p> <div class="exampleInner"> <pre>SE(j:map) <!--key/value pairs--> EE</pre> </div> <p>The XML event sequence for a key/value pair is </p> <div class="exampleInner"> <pre>SE(j:key) <!--value--> EE</pre> </div> <div class="note"> <p class="prefix"> Note: </p> <p>If the key-name is not valid with respect to <cite>NCName</cite> or it conflicts with any existing global element name in the XML schema (e.g., array or string) the key part MUST be escaped as subsequently described in 3.1.1 Key-name Escaping.</p> <p>That said, any escaped character MUST be unescaped to get back the original JSON key-name (see D.3 Example 3).</p> </div> <div class="div3"> <h4> 3.1.1 Key-name Escaping</h4> <p>We distinguish two types of escaping: </p>
                                                    1. <p>Conflict with NCName character(s) </p>
                                                      <p> Any character CharRef that is not valid in XML names for use within XML names MUST be escaped as follows <br> <br> CharRef := '_' [0-9]+ '.' <br> <br> The digits after '_' up to the terminating '.' provide the decimal number of the character's code point.<br>(e.g., JSON key "1 key" becomes "_49._32.key")</p>
                                                      <div class="note"> <p class="prefix"> Note: </p> <p>In order to represent '_' itself, the underscore character needs to be written as "_95." (with period character included) for unambiguous parsing.</p> </div>
                                                    2. <p>Conflict with existing EXI4JSON global schema element name</p>
                                                      <p> If the key-name is one of the reserved EXI4JSON schema element names (map, array, string, number, boolean, null, or other), then the key MUST be prefixed with the following character sequence "_." <br>(e.g., JSON key "map" becomes "_.map")</p>
                                                    </div> </div> <div class="div2"> <h3> 3.2 JSON array </h3> <p>A JSON array is represented as a j:array element which may comprise a collection of values.</p> <div class="exampleInner"> <pre>SE(j:array) <!--values--> EE</pre> </div> </div> <div class="div2"> <h3> 3.3 JSON string </h3> <p>A JSON string MAY be represented as a j:string element.</p> <div class="exampleInner"> <pre>SE(j:string) CH(string-value) EE</pre> </div> <p>The EXI for JSON transformation rules allow to map a string also to one of the following more-optimized XML event sequences</p>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:base64Binary) CH(string-value) EE EE</pre> </div>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:dateTime) CH(string-value) EE EE</pre> </div>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:time) CH(string-value) EE EE</pre> </div>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:date) CH(string-value) EE EE</pre> </div>
                                                    <div class="note"> <p class="prefix"> Note: </p> <p>The above mentioned choice requires that the string-value is representable by the corresponding EXI datatype.</p> </div> </div> <div class="div2"> <h3> 3.4 JSON number </h3> <p>A JSON number MAY be represented as a j:number element.</p> <div class="exampleInner"> <pre>SE(j:number) CH(number-value) EE</pre> </div> <p>The EXI for JSON transformation rules allow to map a number also to one of the following more-optimized XML event sequences</p>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:integer) CH(number-value) EE EE</pre> </div>
                                                    • <div class="exampleInner"> <pre>SE(j:other) SE(j:decimal) CH(number-value) EE EE</pre> </div>
                                                    <div class="note"> <p class="prefix"> Note: </p> <p>The above mentioned choice requires that the number-value is representable by the corresponding EXI datatype.</p> </div> </div> <div class="div2"> <h3> 3.5 JSON true </h3> <p>A JSON true is represented as a j:boolean element with the Characters (CH) event content equals "true".</p> <div class="exampleInner"> <pre>SE(j:boolean) CH("true") EE</pre> </div> </div> <div class="div2"> <h3> 3.6 JSON false </h3> <p>A JSON false is represented as a j:boolean element with the Characters (CH) event content equals "false".</p> <div class="exampleInner"> <pre>SE(j:boolean) CH("false") EE</pre> </div> </div> <div class="div2"> <h3> 3.7 JSON null </h3> <p>A JSON null is represented as an empty j:null element.</p> <div class="exampleInner"> <pre>SE(j:null) EE</pre> </div> </div> </div> </div> <div class="back"> <div class="div1"> <h2> A References</h2> <dl> <dt class="label"> Efficient XML Interchange (EXI) Format 1.0 (Second Edition)</dt> <dd> <cite>Efficient XML Interchange (EXI) Format 1.0 (Second Edition)</cite>, John Schneider, Takuki Kamiya, Daniel Peintner, Rumen Kyusakov, Editors. World Wide Web Consortium. The latest version is available at https://www.w3.org/TR/exi/. (See https://www.w3.org/TR/2014/REC-exi-20140211/.)</dd> <dt class="label"> RFC 7159 - The JavaScript Object Notation (JSON) Data Interchange Format</dt> <dd> <cite>The JavaScript Object Notation (JSON) Data Interchange Format</cite>, T. Bray, Editor. Internet Engineering Task Force (IETF), Request for Comments: 7159. Available at https://tools.ietf.org/html/rfc7159 (See https://tools.ietf.org/html/rfc7159.)</dd> <dt class="label"> ECMA-404 - The JSON Data Interchange Format</dt> <dd> <cite>The JSON Data Interchange Format</cite>, ECMA Standard ECMA-404, first edition, October 2013. Available at http://www.ecma-international.org/publications/standards/Ecma-404.htm (See http://www.ecma-international.org/publications/standards/Ecma-404.htm.)</dd> </dl> </div> <div class="div1"> <h2> B XML Schema for EXI4JSON </h2> <p>The following XML schema describes the EXI4JSON document (see also exi4json.xsd).</p> <div class="exampleInner"> <pre> <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.w3.org/2015/EXI/json" xmlns:j="http://www.w3.org/2015/EXI/json"> <!-- * This is a schema for the XML representation of JSON * * The schema is made available under the terms of the W3C software notice and license * at https://www.w3.org/Consortium/Legal/copyright-software-19980720 * --> <xs:element name="map" type="j:mapType"/> <xs:element name="array" type="j:arrayType"/> <xs:element name="string" type="j:stringType"/> <xs:element name="number" type="j:numberType"/> <xs:element name="boolean" type="j:booleanType"/> <xs:element name="null" type="j:nullType"/> <xs:element name="other" type="j:otherType"/> <xs:complexType name="mapType"> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <!-- any element is a map key which contains the actual value --> <!-- "key": 25 --> <!-- <age> <number>25</number> </age> --> <xs:any processContents="lax" namespace="##targetNamespace"/> </xs:sequence> </xs:complexType> <xs:complexType name="arrayType"> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="j:map"/> <xs:element ref="j:array"/> <xs:element ref="j:string"/> <xs:element ref="j:number"/> <xs:element ref="j:boolean"/> <xs:element ref="j:null"/> <xs:element ref="j:other"/> </xs:choice> </xs:complexType> <xs:simpleType name="stringType"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:simpleType name="numberType"> <xs:restriction base="xs:double"> <!-- exclude positive and negative infinity, and NaN --> <!-- Note: No real effect for EXI Float datatype --> <xs:minExclusive value="-INF"/> <xs:maxExclusive value="INF"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="booleanType"> <xs:restriction base="xs:boolean"/> </xs:simpleType> <xs:complexType name="nullType"/> <xs:complexType name="otherType"> <xs:choice> <!-- useful types beyond JSON such as binary, date-times, decimal and integer --> <xs:element name="base64Binary"> <xs:simpleType> <xs:restriction base="xs:base64Binary"/> </xs:simpleType> </xs:element> <xs:element name="dateTime"> <xs:simpleType> <xs:restriction base="xs:dateTime"/> </xs:simpleType> </xs:element> <xs:element name="time"> <xs:simpleType> <xs:restriction base="xs:time"/> </xs:simpleType> </xs:element> <xs:element name="date"> <xs:simpleType> <xs:restriction base="xs:date"/> </xs:simpleType> </xs:element> <xs:element name="integer"> <xs:simpleType> <xs:restriction base="xs:integer"/> </xs:simpleType> </xs:element> <xs:element name="decimal"> <xs:simpleType> <xs:restriction base="xs:decimal"/> </xs:simpleType> </xs:element> </xs:choice> </xs:complexType> </xs:schema> </pre> </div> </div> <div class="div1"> <h2> C Design Decisions (Non-Normative)</h2> <p>This section discusses a number of key decision points. A rationale for each decision is given and background information is provided.</p> <div class="div2"> <h3> C.1 Selection of other Datatype Representations</h3> <p>Compared to the basic JSON datatypes and the corresponding EXI datatype mapping (i.e., <cite>exi:string</cite>, <cite>exi:double</cite>, and <cite>exi:boolean</cite>) the element other allows for other EXI datatype representations: namely <cite>exi:base64Binary</cite>, <cite>exi:dateTime</cite>, <cite>exi:dateTime</cite>, <cite>exi:time</cite>, <cite>exi:date</cite>, <cite>exi:integer</cite>, and <cite>exi:decimal</cite>.</p> <p>The selection of these additional datatypes is based on their foreseen efficiency and potential usage in JSON documents.</p> </div> <div class="div2"> <h3> C.2 Character Encoding</h3> <p>JSON text may be encoded in UTF-8, UTF-16, or UTF-32 (see <cite>JSON Character Encoding</cite>). EXI for JSON matches the JSON specification in that it does not provide an explicit label for the included characters.</p> <p>If possible without loss of correctness, processors are recommended to use the default UTF-8 for maximum interoperability when creating JSON documents.</p> </div> <div class="div2"> <h3> C.3 Selection of EXI options</h3> <p> EXI for JSON defines a set of predefined EXI Options beyond the default <cite>EXI Options</cite>.</p> <div class="div3"> <h4> C.3.1 EXI Option strict </h4> <p>The default EXI value for strict is false to permit event items not declared in the schemas. </p> <p>The main reason to set strict to true in the EXI for JSON context is to reduce specification and code complexity while at the same time allowing for simple implementations. In section 3. Representing JSON data using EXI it is specified how to map an EXI4JSON stream to JSON. Allowing strict to be false would require to deal with unexpected elements and/or attributes and would make the specification more complex while at the same time increase code complexity. The working group concluded that strict being false does not provide any benefit in this context.</p> <p>Besides that strict being true increases compactness and allows for realizing more-optimized processors with less code.</p> </div> <div class="div3"> <h4> C.3.2 EXI Option schemaId </h4> <p>The <cite>schemaId</cite> is used to identify the schema information used for processing the EXI stream. The value "exi4json" has been chosen to identify the schema in Appendix B XML Schema for EXI4JSON.</p> </div> </div> <div class="div2"> <h3> C.4 Change of Structure</h3> <p>The EXI for JSON structure has been changed compared to the previous publication. A JSON key is not represented anymore as attribute. Instead it is transformed to an element with the JSON value as nested element. </p> <p>The reason for this change is to allow for dedicated XML schema definitions (which were not possible before). This change implied escaping (see 3.1.1 Key-name Escaping) with the positive side effect to generate valid XML streams.</p> <div class="note"> <p class="prefix"> Note: </p> <p>EXI streams would not need escaping.</p> </div> </div> </div> <div class="div1"> <h2> D Examples (Non-Normative)</h2> <div class="div2"> <h3> D.1 Example 1</h3> <p>This example illustrates a simple JSON document with a numbered value and an array of strings.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON </th><td></td><th> EXI4JSON </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "keyNumber": 123, "keyArrayStrings": [ "s1", "s2" ] } </pre> </div> </td><td style=" vertical-align: top;">↔</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <j:map xmlns:j="http://www.w3.org/2015/EXI/json"> <j:keyNumber> <j:number>123</j:number> </j:keyNumber> <j:keyArrayStrings> <j:array> <j:string>s1</j:string> <j:string>s2</j:string> </j:array> </j:keyArrayStrings> </j:map> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> D.2 Example 2</h3> <p>This is example illustrates nested JSON values such as objects and arrays.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON </th><td></td><th> EXI4JSON </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "glossary": { "title": "example glossary", "GlossDiv": { "title": "S", "GlossList": { "GlossEntry": { "ID": "SGML", "SortAs": "SGML", "GlossTerm": "Standard Generalized Markup Language", "Acronym": "SGML", "Abbrev": "ISO 8879:1986", "GlossDef": { "para": "A meta-markup language, used to create markup languages such as DocBook.", "GlossSeeAlso": [ "GML", "XML" ] }, "GlossSee": "markup" } } } } } </pre> </div> </td><td style=" vertical-align: top;">↔</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <j:map xmlns:j="http://www.w3.org/2015/EXI/json"> <j:glossary> <j:map> <j:title> <j:string>example glossary</j:string> </j:title> <j:GlossDiv> <j:map> <j:title> <j:string>S</j:string> </j:title> <j:GlossList> <j:map> <j:GlossEntry> <j:map> <j:ID> <j:string>SGML</j:string> </j:ID> <j:SortAs> <j:string>SGML</j:string> </j:SortAs> <j:GlossTerm> <j:string>Standard Generalized Markup Language</j:string> </j:GlossTerm> <j:Acronym> <j:string>SGML</j:string> </j:Acronym> <j:Abbrev> <j:string>ISO 8879:1986</j:string> </j:Abbrev> <j:GlossDef> <j:map> <j:para> <j:string>A meta-markup language, used to create markup languages such as DocBook.</j:string> </j:para> <j:GlossSeeAlso> <j:array> <j:string>GML</j:string> <j:string>XML</j:string> </j:array> </j:GlossSeeAlso> </j:map> </j:GlossDef> <j:GlossSee> <j:string>markup</j:string> </j:GlossSee> </j:map> </j:GlossEntry> </j:map> </j:GlossList> </j:map> </j:GlossDiv> </j:map> </j:glossary> </j:map> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> D.3 Example 3</h3> <p>This is an example with a keyname "a number" which is not valid with respect to NCName and uses 3.1.1 Key-name Escaping.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON </th><td></td><th> EXI4JSON </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "a number": 1 } </pre> </div> </td><td style=" vertical-align: top;">↔</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <j:map xmlns:j="http://www.w3.org/2015/EXI/json"> <j:a_32.number> <j:number>1</j:number> </j:a_32.number> </j:map> </pre> </div> </td> </tr> </tbody> </table> </div> </div> <div class="div1"> <h2> E Schema Mapping (Non-Normative)</h2> <p>This section describes best practices in how to map knowledge of JSON data into dedicated XML schema definitions. Dedicated XML schema definitions (compared to the pre-defined "exi4json" schemaId specified in this document) allow for an even more efficient representation by keeping compatibility on a structural basis.</p> <p>Note: JSON schema is used in the examples but the practices are not limited to JSON schema language.</p> <table style="border: 1px;"> <tr> <td style="text-align: left; vertical-align:top; width: 50%;">Editorial note</td><td style="text-align: right; vertical-align:top; width: 50%;"> </td> </tr> <tr style="text-align: left; vertical-align: top;"> <td colspan="2">Add information about JSON schema "additionalProperties": false/true</td> </tr> </table> <div class="div2"> <h3> E.1 JSON object</h3> <p>A JSON object is mapped to an element with complexType and the name attribute set to map. The child elements appear in all so that they can appear in any order. The attribute minOccurs is set to "0" if a child element is not required.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "object", "properties": { "firstname": { "type": "string" }, "lastname": { "type": "string" }, "age": { "type": "number" } }, "required": [ "lastname", "age" ] } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="map"> <complexType> <all> <element minOccurs="0" name="firstname"> <complexType> <sequence> <!--unnamed-format--> <element name="string" type="string"/> </sequence> </complexType> </element> <element name="age"> <complexType> <sequence> <element name="number" type="double"/> </sequence> </complexType> </element> <element name="lastname"> <complexType> <sequence> <!--unnamed-format--> <element name="string" type="string"/> </sequence> </complexType> </element> </all> </complexType> </element> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.2 JSON array</h3> <p>A JSON array is mapped to an element with complexType and the name attribute set to array. The child elements appear in a sequence and the attribute minOccurs is set to "0" and maxOccurs to "unbounded". The child elements itself depend on the items type.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "array", "items": { "type": "number" } } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="array"> <complexType> <sequence maxOccurs="unbounded" minOccurs="0"> <element name="number" type="double"/> </sequence> </complexType> </element> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.3 JSON string</h3> <p>A JSON string is mapped to an element with the name attribute set to string and typed as string.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "string" } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="string" type="string"/> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.4 JSON number</h3> <p>A JSON number is mapped to an element with the name attribute set to number and typed as double.</p> <table style="border: 1px;"> <tr> <td style="text-align: left; vertical-align:top; width: 50%;">Editorial note</td><td style="text-align: right; vertical-align:top; width: 50%;"> </td> </tr> <tr style="text-align: left; vertical-align: top;"> <td colspan="2">Differentiate between "number" and "integer".</td> </tr> </table> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "number" } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="number" type="double"/> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.5 JSON boolean</h3> <p>A JSON boolean is mapped to an element with the name attribute set to boolean and typed as boolean.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "boolean" } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="boolean" type="boolean"/> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.6 JSON null</h3> <p>A JSON null is mapped to an element with the name attribute set to null and typed as empty complexType.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "null" } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="null"> <complexType/> </element> </pre> </div> </td> </tr> </tbody> </table> </div> <div class="div2"> <h3> E.7 JSON enumeration</h3> <p>A JSON enumeration is mapped to an element based on the desired type.</p> <table style="padding: 5px;"> <tbody> <tr> <th> JSON schema </th><td></td><th> XML schema definition </th> </tr> <tr> <td style=" vertical-align: top;"> <div class="exampleInner"> <pre> { "type": "string", "enum": ["red", "amber", "green"] } </pre> </div> </td><td style=" vertical-align: top;">→</td><td style=" vertical-align: top;"> <div class="exampleInner"> <pre> <element name="string"> <simpleType> <restriction base="string"> <enumeration value="red"/> <enumeration value="green"/> <enumeration value="amber"/> </restriction> </simpleType> </element> </pre> </div> </td> </tr> </tbody> </table> </div> </div> <div class="div1"> <h2> F Acknowledgements (Non-Normative)</h2> <p>This document is the work of the Efficient XML Interchange (EXI) WG.</p> <p>Members of the Working Group are (at the time of writing, sorted alphabetically by last name): </p>
                                                    • <p>Carine Bournez, W3C/ERCIM (staff contact)</p>
                                                    • <p>Don Brutzman, Web3D Consortium</p>
                                                    • <p>Michael Cokus, MITRE Corporation</p>
                                                    • <p>Fernández, Javier D., Vienna University of Economics and Business</p>
                                                    • <p>Joerg Heuer, Siemens AG</p>
                                                    • <p>Sebastian Käbisch, Siemens AG</p>
                                                    • <p>Takuki Kamiya, Fujitsu Laboratories of America (chair)</p>
                                                    • <p>Richard Kuntschke, Siemens AG</p>
                                                    • <p>Matsukura, Ryuichi, Fujitsu Laboratories</p>
                                                    • <p>Don McGregor, Web3D Consortium</p>
                                                    • <p>Daniel Peintner, Siemens AG</p>
                                                    • <p>Liam Quin, W3C/MIT</p>
                                                    • <p>Mohamed Zergaoui, INNOVIMAX</p>
                                                    <p>The EXI Working Group would like to acknowledge the following former members or external experts for their leadership, guidance and expertise they provided throughout the process of creating this document (sorted alphabetically by last name): </p>
                                                    • <p>Yusuke Doi</p>
                                                    • <p>Youenn Fablet</p>
                                                    • <p>Bruce Hill</p>
                                                    • <p>Rumen Kyusakov</p>
                                                    • <p>Stephen Williams</p>
                                                    • <p>Brett Zamir</p>
                                                    <p>The EXI Working Group especially acknowledges and thanks Liam Quin (W3C/MIT) for his guidance and insight throughout the development of the EXI family of recommendations. </p> </div> </div> <script src="//www.w3.org/scripts/TR/2016/fixup.js"></script> </body> </html>
                                                    View source
                                                  3. <?xml version="1.0" encoding="UTF-8"?>
                                                    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
                                                        targetNamespace="http://www.w3.org/2015/EXI/json" xmlns:j="http://www.w3.org/2015/EXI/json">
                                                    
                                                        <!-- 
                                                         * This is a schema for the XML representation of JSON 
                                                         *
                                                         * The schema is made available under the terms of the W3C software notice and license
                                                         * at https://www.w3.org/Consortium/Legal/copyright-software-19980720
                                                         *
                                                        -->
                                                    
                                                        <xs:element name="map" type="j:mapType"/>
                                                    
                                                        <xs:element name="array" type="j:arrayType"/>
                                                    
                                                        <xs:element name="string" type="j:stringType"/>
                                                    
                                                        <xs:element name="number" type="j:numberType"/>
                                                    
                                                        <xs:element name="boolean" type="j:booleanType"/>
                                                    
                                                        <xs:element name="null" type="j:nullType"/>
                                                    
                                                        <xs:element name="other" type="j:otherType"/>
                                                    
                                                    
                                                        <xs:complexType name="mapType">
                                                            <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                                                <!-- any element is a map key which contains the actual value  -->
                                                                <!-- "key": 25 -->
                                                                <!-- 
                                                                    <age>
                                                                        <number>25</number>
                                                                    </age>
                                                                -->
                                                                <xs:any processContents="lax" namespace="##targetNamespace"/>
                                                            </xs:sequence>
                                                        </xs:complexType>
                                                    
                                                        <xs:complexType name="arrayType">
                                                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                                                <xs:element ref="j:map"/>
                                                                <xs:element ref="j:array"/>
                                                                <xs:element ref="j:string"/>
                                                                <xs:element ref="j:number"/>
                                                                <xs:element ref="j:boolean"/>
                                                                <xs:element ref="j:null"/>
                                                                <xs:element ref="j:other"/>
                                                            </xs:choice>
                                                        </xs:complexType>
                                                    
                                                        <xs:simpleType name="stringType">
                                                            <xs:restriction base="xs:string"/>
                                                        </xs:simpleType>
                                                    
                                                        <xs:simpleType name="numberType">
                                                            <xs:restriction base="xs:double">
                                                                <!-- exclude positive and negative infinity, and NaN -->
                                                                <!-- Note: No real effect for EXI Float datatype -->
                                                                <xs:minExclusive value="-INF"/>
                                                                <xs:maxExclusive value="INF"/>
                                                            </xs:restriction>
                                                        </xs:simpleType>
                                                    
                                                        <xs:simpleType name="booleanType">
                                                            <xs:restriction base="xs:boolean"/>
                                                        </xs:simpleType>
                                                    
                                                        <xs:complexType name="nullType"/>
                                                    
                                                        <xs:complexType name="otherType">
                                                            <xs:choice>
                                                                <!-- useful types beyond JSON such as binary, date-times, decimal and integer -->
                                                                <xs:element name="base64Binary">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:base64Binary"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                                <xs:element name="dateTime">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:dateTime"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                                <xs:element name="time">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:time"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                                <xs:element name="date">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:date"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                                <xs:element name="integer">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:integer"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                                <xs:element name="decimal">
                                                                    <xs:simpleType>
                                                                        <xs:restriction base="xs:decimal"/>
                                                                    </xs:simpleType>
                                                                </xs:element>
                                                            </xs:choice>
                                                        </xs:complexType>
                                                    
                                                    </xs:schema>
                                                    
                                                    View source