Network Working Group B. Muschett Internet-Draft R. Salz Expires: November 3, 2011 M. Schenker IBM May 2, 2011 JSONx, an XML Encoding for JSON draft-rsalz-jsonx-00.txt Abstract This document specifies a mapping between JSON (RFC 4627) and XML. The mapping maintains a high degree of fidelity. It is used by several IBM products. Status of this Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at http://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on November 3, 2011. Copyright Notice Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Muschett, et al. Expires November 3, 2011 [Page 1] Internet-Draft JSONx May 2011 Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Conversion Rules . . . . . . . . . . . . . . . . . . . . . . . 4 2.1. root element . . . . . . . . . . . . . . . . . . . . . . . 4 2.2. object . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.3. array . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.4. boolean . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.5. string . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.6. number . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.7. null . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3. Extended Example . . . . . . . . . . . . . . . . . . . . . . . 7 4. Normative References . . . . . . . . . . . . . . . . . . . . . 8 Appendix A. Schema (not normative) . . . . . . . . . . . . . . . 9 Appendix B. JSONx to JSON Stylesheet (not normative) . . . . . . 11 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 13 Muschett, et al. Expires November 3, 2011 [Page 2] Internet-Draft JSONx May 2011 1. Introduction This document specifies a mapping between JSON [RFC4627] and XML, known as JSONx. The mapping maintains a high degree of fidelity. It is used by several IBM products. JSONx is specified using the terms from the XML Infoset [REC-xml-infoset], serialized as XML 1.0 [REC-xml]. The Infoset terms "Element Information Item," "Attribute Information Item," and "Character Information Item," are shortened to "element," "attribute," and "characters" respectively. For example, when this specification uses the term "element," it is referring to an Element Information Item, and when it uses the term "attribute," it is referring to an Attribute Information Item. Muschett, et al. Expires November 3, 2011 [Page 3] Internet-Draft JSONx May 2011 2. Conversion Rules JSON identifiers are represented by the string contents of the "name" attribute. Most Unicode characters other than backspace (Unicode code point U+0008) and form feed (U+000C) are valid within identifiers, as long as they are properly escaped (for example, \unnnn). When JSONx is serialized as XML documents, character and/or entity references may need to be used for special characters. Examples of this include ampersand (U+0026), less-then sign (U+003C), and any characters not representable in the document's encoding. Use of backspace, formfeed, or NUL (U+0000) is undefined. 2.1. root element The root element is either a or a element with the following namespace declaration: +--------+------------------------------------------+ | Prefix | Namespace URI | +--------+------------------------------------------+ | json | http://www.ibm.com/xmlns/prod/2009/jsonx | +--------+------------------------------------------+ All elements defined in this document are in that namespace. 2.2. object A JSON object becomes a element. If the object denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. The child elements depend on the properties of the JSON object. To improve readability, whitespace characters may be added between child elements. Object elements are ordered according to their document order. { "Ticker" : "IBM" } IBM 2.3. array A JSON array becomes a element. If the array denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. The child elements depend on the values in the array. To improve readability, whitespace characters may be added between child elements. Muschett, et al. Expires November 3, 2011 [Page 4] Internet-Draft JSONx May 2011 "phoneNumbers": [ "212 555-1111", "212 555-2222" ] 212 555-1111 212 555-2222 2.4. boolean A JSON boolean becomes a element. If the boolean denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. The boolean value is character data as either true or false. "remote": false false 2.5. string A JSON string becomes a element. If the string denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. The string value is character data. Use of the Unicode code points U+0000, U+0008, and U+000C is undefined. "name": "John Smith" John Smith 2.6. number A JSON number becomes a element. If the number denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. The number value is character data. "height": 62.4 62.4 Muschett, et al. Expires November 3, 2011 [Page 5] Internet-Draft JSONx May 2011 2.7. null JSON value of null becomes a element. If the null value denotes a property within a JSON object, JSONx encodes a name attribute whose value is assigned the property name. This element has no content. "additionalInfo": null Muschett, et al. Expires November 3, 2011 [Page 6] Internet-Draft JSONx May 2011 3. Extended Example The following example document is a sample of the JSON structure. { "name": "John Smith" "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": 10021, }, "phoneNumbers": [ "212 555-1111", "212 555-2222" ], "additionalInfo": null, "remote": false, "height": 62.4, "ficoScore": "> 640" } The following output is the result of the transformed document as JSONx. John Smith 21 2nd Street New York NY 10021 212 555-1111 212 555-2222 false 62.4 > 640 Muschett, et al. Expires November 3, 2011 [Page 7] Internet-Draft JSONx May 2011 4. Normative References [RFC4627] Crockford, D., "The application/json Media Type for JavaScript Object Notation (JSON)", RFC 4627, July 2006. [REC-xml] Yergeau, F., Paoli, J., Bray, T., Sperberg-McQueen, C., and E. Maler, "Extensible Markup Language (XML) 1.0 (Fourth Edition)", World Wide Web Consortium Recommendation REC-xml-20060816, August 2006, . [REC-xml-infoset] Cowan, J. and R. Tobin, "XML Information Set (Second Edition)", World Wide Web Consortium Recommendation REC- xml-infoset-20040204, February 2004, . Muschett, et al. Expires November 3, 2011 [Page 8] Internet-Draft JSONx May 2011 Appendix A. Schema (not normative) Muschett, et al. Expires November 3, 2011 [Page 9] Internet-Draft JSONx May 2011 Muschett, et al. Expires November 3, 2011 [Page 10] Internet-Draft JSONx May 2011 Appendix B. JSONx to JSON Stylesheet (not normative) The following XSLT stylesheet takes a JSONx document as input and generates JSON. It is intended as a sample implementation, and makes no attempt to be well-behaved if the input is not well-defined. { , } [ , ] " Muschett, et al. Expires November 3, 2011 [Page 11] Internet-Draft JSONx May 2011 " null Muschett, et al. Expires November 3, 2011 [Page 12] Internet-Draft JSONx May 2011 Authors' Addresses Brien Muschett IBM 8051 Congress Avenue Boca Raton, FL 33487 USA Phone: +1 561-862-2180 Email: muschett@us.ibm.com Rich Salz IBM 550 King Street Littleton, MA 01460 USA Phone: +1 978-899-2902 Email: rsalz@us.ibm.com URI: https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/ Michael Schenker IBM 555 Bailey Ave. San Jose, CA 95141 USA Phone: +1 408-463-3907 Email: mschenk@us.ibm.com Muschett, et al. Expires November 3, 2011 [Page 13]