<?xml version="1.0" encoding="us-ascii"?>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc strict="yes" ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>

<rfc category="info" docName="draft-rundgren-comparable-json-00" ipr="trust200902">
  <front>
    <title abbrev="draft-rundgren-comparable-json">
      "Comparable" JSON (JSONCOMP)
    </title>

    <author fullname="Anders Rundgren" initials="A." surname="Rundgren">
      <organization>Independent</organization>
      <address>
        <postal>
          <street></street>
          <code></code>
          <city>Montpellier</city>
          <country>France</country>
        </postal>
        <email>anders.rundgren.net@gmail.com</email>
        <uri>https://www.linkedin.com/in/andersrundgren/</uri>
      </address>
    </author>

    <date year="2019" />

    <area>Security</area>

    <workgroup></workgroup>

    <keyword>
      JSON, ECMAScript, Canonicalization, Normalization
    </keyword>

    <abstract>
      <t>
        This application note describes how JCS <xref target="JCS"/>
        can be utilized to support applications needing canonicalization
        beyond the core JSON <xref target="RFC8259"/> level,
        with comparisons as the primary target.
      </t>
    </abstract>
  </front>

  <middle>
    <section anchor="Introduction" title="Introduction">
      <t>
        The purpose of JCS <xref target="JCS"/> is creating "Hashable" JSON <xref target="RFC8259"/>
        data intended for cryptographic solutions.
        JCS accomplishes this by combining normalization of the native JSON
        String and Number primitives with a deterministic property sorting scheme.
        That is, JCS provides canonicalization at the core JSON level.
        For interoperability reasons JCS also constrains data to the I-JSON <xref target="RFC7493"/> subset.
      </t>
      <t>
        However, if you rather would like to compare JSON data from
        different sources or runs, JCS would in many cases be
        inadequate since the JSON String type is commonly used
        for holding subtypes like "DateTime" or "BigNumber" objects.
      </t>
      <t>
        This application note outlines how JCS in spite of having a limited
        canonicalization scope still may be utilized by applications like above.
      </t>
    </section>

    <section anchor="Terminology" title="Terminology">
      <t>
        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
        NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
        "MAY", and "OPTIONAL" in this document are to be interpreted as
        described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/>
        when, and only when, they appear in all capitals, as shown here.
      </t>
    </section>

    <section anchor="string.subtypes" title="String Subtype Normalization">
      <t>
        Assume you want to compare productions of JSON data where the schema
        designer assigned the property "big" for holding a "BigInteger" subtype and
        "time" for holding a "DateTime" subtype, while "val" is supposed to be a JSON Number
        compliant with JCS. The example below shows such a string:
      </t>
      <t>
        <figure align="center">
          <artwork><![CDATA[  {"time": "2019-01-28T07:45:10Z", "big": "055", "val": 3.5}]]></artwork>
        </figure>
      </t>
      <t>
        A problem here is that "055" clearly is not a canonical form for a "BigInteger"
        while a "DateTme" object like "2019-01-28T07:45:10Z"
        might as well be expressed as "2019-01-28T08:45:10.000+01:00" making
        comparisons based on JCS canonicalization fail.
      </t>
      <t>
        To resolve this issue using JCS the following measures MUST be taken:
        <list style="symbols">
          <t>
            The community or standard utilizing a specific JSON schema
            defines a strict normalized form for each of the used subtypes.
          </t>
          <t>
            Compatible serializers are created for each subtype.
          </t>
        </list>
          A positive side effect of this arrangement is that it enforces strict definitions
          of subtypes which improves interoperability in general as well.
      </t>
      <t>
        Below is an example how such a serializer could be expressed in ECMAScript <xref target="ECMASCRIPT"/> 
        for a "DateTime" subtype:
      </t>
        <t>
          <figure align="center"><artwork><![CDATA[  Date.prototype.toJSON = function() {
      let date = this.toISOString();
      // In this particular case we selected a UTC notation
      // yyyy-mm-ddThh:mm:ssZ
      return date.substring(0, date.indexOf('.')) + 'Z';
  };]]></artwork></figure>
        </t>
        <t>
          Defining specific subtypes and their normalized form is out of scope for
          this application note.
        </t>
      </section>
 
    <section anchor="IANA" title="IANA Considerations">
      <t>
        This document has no IANA actions.
      </t>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t>
        TBD.
      </t>
    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>
        TBD.
      </t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include='reference.RFC.2119'?>
      <?rfc include='reference.RFC.8259'?>
      <?rfc include='reference.RFC.8174'?>
      <?rfc include='reference.RFC.7493'?>
      <reference anchor="JCS" target="https://tools.ietf.org/html/draft-rundgren-json-canonicalization-scheme-04">
        <front>
          <title>JSON Canonicalization Scheme - Work in progress</title>
          <author>
            <organization>A. Rundgren, B. Jordan, S. Erdtman</organization>
          </author>
          <date/>
        </front>
      </reference>
    </references>
    <references title="Informal References">
      <reference anchor="ECMASCRIPT" target="https://www.ecma-international.org/ecma-262/6.0/index.html">
        <front>
          <title>ECMAScript 2015 Language Specification</title>
          <author>
            <organization>Ecma International</organization>
          </author>
          <date/>
        </front>
      </reference>
    </references>
  </back>
</rfc>
