1
0
mirror of https://github.com/moparisthebest/xeps synced 2024-11-25 02:32:18 -05:00
xeps/xep-0335.xml

132 lines
6.8 KiB
XML
Raw Normal View History

2013-10-09 11:16:47 -04:00
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
<title>JSON Containers</title>
<abstract>This specification defines an element to be used for encapsulating JSON data in XMPP.</abstract>
2013-10-25 12:17:14 -04:00
&LEGALNOTICE;
<number>0335</number>
<status>Experimental</status>
2019-02-04 10:40:39 -05:00
<lastcall>2019-02-19</lastcall>
2013-10-09 11:16:47 -04:00
<type>Standards Track</type>
<sig>Standards</sig>
<approver>Council</approver>
<dependencies>
<spec>XMPP Core</spec>
2013-10-10 18:46:39 -04:00
<spec>RFC 4627</spec>
2013-10-09 11:16:47 -04:00
</dependencies>
<supersedes/>
<supersededby/>
<shortname>NOT_YET_ASSIGNED</shortname>
&mwild;
2018-09-26 11:11:20 -04:00
<revision>
<version>0.1.1</version>
<date>2018-09-26</date>
<initials>pep</initials>
<remark><p>Fix XEP number in schema description</p></remark>
</revision>
2013-10-25 12:17:14 -04:00
<revision>
<version>0.1</version>
<date>2013-10-25</date>
<initials>psa</initials>
<remark><p>Initial published version approved by the XMPP Council.</p></remark>
</revision>
2013-10-10 18:46:39 -04:00
<revision>
<version>0.0.2</version>
<date>2013-10-09</date>
<initials>mw</initials>
<remark><p>Update namespace to urn:xmpp:json:0, add requirement for encapsulation within other protocols, and require conformance to RFC 4627.</p></remark>
</revision>
2013-10-09 11:16:47 -04:00
<revision>
<version>0.0.1</version>
<date>2012-11-15</date>
<initials>mw</initials>
<remark><p>First draft.</p></remark>
</revision>
</header>
<section1 topic='Introduction' anchor='intro'>
<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>
<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>
<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>
</section1>
<section1 topic='Requirements' anchor='reqs'>
2013-10-10 18:46:39 -04:00
<p>This specification should:</p>
2013-10-09 11:16:47 -04:00
<ul>
<li>Allow stanza generators to unambiguously embed JSON within their stanzas.</li>
<li>Allow stanza recipients a way to identify JSON content, and thus also validation.</li>
</ul>
</section1>
<section1 topic='Use Cases' anchor='usecases'>
2013-10-10 18:46:39 -04:00
<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>
<example caption='JSON as a pubsub item payload'><![CDATA[
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='princely_musings'>
<item id='ae890ac52d0df67ed7cfdf51b644e901'>
<json xmlns="urn:xmpp:json:0">
{ "name": "romeo", "age": "421", "status": "single" }
</json>
</item>
</items>
</event>
</message>
]]></example>
2013-10-09 11:16:47 -04:00
2013-10-10 18:46:39 -04:00
<example caption='JSON as part of a custom protocol'><![CDATA[
2013-10-09 11:16:47 -04:00
<iq to="recipient.example.com" type="get" id="q1">
<query xmlns="http://example.com/user-queries">
2013-10-10 18:46:39 -04:00
<json xmlns="urn:xmpp:json:0">
2013-10-09 11:16:47 -04:00
{ "name": "romeo" }
</json>
</query>
</iq>
]]></example>
2013-10-09 11:16:47 -04:00
</section1>
<section1 topic='Business Rules' anchor='rules'>
2013-10-10 18:46:39 -04:00
<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>
2013-10-09 11:16:47 -04:00
<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>
2013-10-10 18:46:39 -04:00
<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>
2013-10-09 11:16:47 -04:00
</section1>
<section1 topic='Implementation Notes' anchor='notes'>
<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>
<p>When generating stanzas containing JSON payloads, implementations should be aware of the maximum stanza size considerations laid down in &xmppcore;.</p>
<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>
</section1>
<section1 topic='Security Considerations' anchor='security'>
<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>
</section1>
<section1 topic='IANA Considerations' anchor='iana'>
<p>N/A.</p>
</section1>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
<p>TBD.</p>
</section1>
<section1 topic='XML Schema' anchor='schema'>
<p>This schema is descriptive, not normative.</p>
<code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema
xmlns:xs='http://www.w3.org/2001/XMLSchema'
2013-10-10 18:46:39 -04:00
targetNamespace='urn:xmpp:json:0'
xmlns='urn:xmpp:json:0'
2013-10-09 11:16:47 -04:00
elementFormDefault='qualified'>
<xs:annotation>
<xs:documentation>
The protocol documented by this schema is defined in
XEP-0335: http://www.xmpp.org/extensions/xep-0335.html
2013-10-09 11:16:47 -04:00
</xs:documentation>
</xs:annotation>
<xs:element name='json' type='xs:string' minOccurs='0' maxOccurs='unbounded'/>
</xs:schema>
]]></code>
2013-10-09 11:16:47 -04:00
</section1>
</xep>