No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0335.xml 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>JSON Containers</title>
  10. <abstract>This specification defines an element to be used for encapsulating JSON data in XMPP.</abstract>
  11. &LEGALNOTICE;
  12. <number>0335</number>
  13. <status>Deferred</status>
  14. <type>Standards Track</type>
  15. <sig>Standards</sig>
  16. <approver>Council</approver>
  17. <dependencies>
  18. <spec>XMPP Core</spec>
  19. <spec>RFC 4627</spec>
  20. </dependencies>
  21. <supersedes/>
  22. <supersededby/>
  23. <shortname>NOT_YET_ASSIGNED</shortname>
  24. &mwild;
  25. <revision>
  26. <version>0.1</version>
  27. <date>2013-10-25</date>
  28. <initials>psa</initials>
  29. <remark><p>Initial published version approved by the XMPP Council.</p></remark>
  30. </revision>
  31. <revision>
  32. <version>0.0.2</version>
  33. <date>2013-10-09</date>
  34. <initials>mw</initials>
  35. <remark><p>Update namespace to urn:xmpp:json:0, add requirement for encapsulation within other protocols, and require conformance to RFC 4627.</p></remark>
  36. </revision>
  37. <revision>
  38. <version>0.0.1</version>
  39. <date>2012-11-15</date>
  40. <initials>mw</initials>
  41. <remark><p>First draft.</p></remark>
  42. </revision>
  43. </header>
  44. <section1 topic='Introduction' anchor='intro'>
  45. <p><link url='http://json.org/'>JSON</link> is an increasingly popular format for data representation. While investigation has shown us that it cannot feasibly replace XML in all its uses (&xep0295;) sometimes existing data is already in JSON or it is necessary to integrate with systems that use JSON while avoiding the overhead of marshalling that data to or from XML.</p>
  46. <p>Traditional approaches have ranged from simply placing the XML into existing freeform text containers in XMPP (such as the message &lt;body&gt; tag or the presence &lt;status&gt; tag) to creating dedicated containers in a custom namespace. Neither of these approaches are ideal for preserving the extensibility or interoperability that XMPP provides.</p>
  47. <p>This document aims to solve the problem by defining a standard way to embed JSON into any XMPP stanza, and even allowing its use with existing XMPP protocols where possible.</p>
  48. </section1>
  49. <section1 topic='Requirements' anchor='reqs'>
  50. <p>This specification should:</p>
  51. <ul>
  52. <li>Allow stanza generators to unambiguously embed JSON within their stanzas.</li>
  53. <li>Allow stanza recipients a way to identify JSON content, and thus also validation.</li>
  54. </ul>
  55. </section1>
  56. <section1 topic='Use Cases' anchor='usecases'>
  57. <p>Since JSON generally isn't designed for end-user presentation, most use-cases centre around JSON as part of machine-to-machine communication, or as part of a higher protocol, such as &xep0060;.</p>
  58. <example caption='JSON as a pubsub item payload'><![CDATA[
  59. <message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
  60. <event xmlns='http://jabber.org/protocol/pubsub#event'>
  61. <items node='princely_musings'>
  62. <item id='ae890ac52d0df67ed7cfdf51b644e901'>
  63. <json xmlns="urn:xmpp:json:0">
  64. { "name": "romeo", "age": "421", "status": "single" }
  65. </json>
  66. </item>
  67. </items>
  68. </event>
  69. </message>
  70. ]]></example>
  71. <example caption='JSON as part of a custom protocol'><![CDATA[
  72. <iq to="recipient.example.com" type="get" id="q1">
  73. <query xmlns="http://example.com/user-queries">
  74. <json xmlns="urn:xmpp:json:0">
  75. { "name": "romeo" }
  76. </json>
  77. </query>
  78. </iq>
  79. ]]></example>
  80. </section1>
  81. <section1 topic='Business Rules' anchor='rules'>
  82. <p>The &lt;json&gt; element MUST only contain character data, and the data MUST conform to &rfc4627;. Specifically, the element MUST NOT be empty, as the empty string is not valid JSON. The data MUST be encoded as UTF-8 (though officially unspecified, this is the de facto encoding for JSON today).</p>
  83. <p>Implementations SHOULD validate JSON they receive and intend to use, and be prepared to handle invalid data appropriately (such as by responding to the sender with the applicable XMPP error reply for the stanza type).</p>
  84. <p>As the &lt;json&gt; element alone provides no context to the recipient about the kind of data it contains, only the format, it SHOULD always be encapsulated within another element that provides a context and SHOULD NOT be added as a direct child of a stanza.</p>
  85. </section1>
  86. <section1 topic='Implementation Notes' anchor='notes'>
  87. <p>The JSON container element is intended for communicating small pieces of generic JSON data within a particular context. XMPP entities MUST NOT attempt to interpret unexpected JSON data they receive, and servers SHOULD NOT inspect JSON data inside stanzas they are routing, other than for OPTIONAL validation.</p>
  88. <p>When generating stanzas containing JSON payloads, implementations should be aware of the maximum stanza size considerations laid down in &xmppcore;.</p>
  89. <p>Embedding JSON is not intended as a substitute for the use of XML in XMPP, and no attempt should be made by protocol designers to use it as such. XMPP implementations are optimised for XML processing, and introducing mixed-format protocols on top of existing XMPP constructs could lead to performance and security considerations beyond the scope of this document.</p>
  90. </section1>
  91. <section1 topic='Security Considerations' anchor='security'>
  92. <p>JSON is a very common format for data interchange today, and has many popular implementations available in browsers and standalone libraries that can be assumed relatively well-tested. However an implementation receiving JSON data from an untrusted entity should take precautions and MUST NOT attempt to use invalid JSON data it receives in any way, nor must it accept data in any encoding other than UTF-8 to avoid potential encoding mismatch attacks.</p>
  93. </section1>
  94. <section1 topic='IANA Considerations' anchor='iana'>
  95. <p>N/A.</p>
  96. </section1>
  97. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  98. <p>TBD.</p>
  99. </section1>
  100. <section1 topic='XML Schema' anchor='schema'>
  101. <p>This schema is descriptive, not normative.</p>
  102. <code><![CDATA[
  103. <?xml version='1.0' encoding='UTF-8'?>
  104. <xs:schema
  105. xmlns:xs='http://www.w3.org/2001/XMLSchema'
  106. targetNamespace='urn:xmpp:json:0'
  107. xmlns='urn:xmpp:json:0'
  108. elementFormDefault='qualified'>
  109. <xs:annotation>
  110. <xs:documentation>
  111. The protocol documented by this schema is defined in
  112. XEP-xxxx: http://www.xmpp.org/extensions/xep-xxxx.html
  113. </xs:documentation>
  114. </xs:annotation>
  115. <xs:element name='json' type='xs:string' minOccurs='0' maxOccurs='unbounded'/>
  116. </xs:schema>
  117. ]]></code>
  118. </section1>
  119. </xep>