<?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.11 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?rfc toc="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>

<rfc ipr="trust200902" docName="draft-jonas-json-template-language-00" category="info">

  <front>
    <title abbrev="JSON Templates">JSON Template Language</title>

    <author initials="S." surname="Jonas" fullname="Shane Jonas">
      <organization>ETC Labs Core</organization>
      <address>
        <email>shane.j@etclabs.org</email>
      </address>
    </author>

    <date year="2019" month="March" day="29"/>

    <area>General</area>
    
    <keyword>Internet-Draft</keyword>

    <abstract>


<t>JSON Template Language is a simple, compact template language to substitute <eref target="https://tools.ietf.org/html/rfc7159">JSON</eref> into a template. It is derived from the template literals of Javascript, as defined in the ECMAScript Programming Language Standard, Ninth Edition <eref target="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-template-literals">ECMA-262</eref>. It has uses not limited to: specifying interfaces, runtime expression mapping, and other forms of programmatically interacting with JSON and templates.</t>



    </abstract>


  </front>

  <middle>


<section anchor="introduction" title="Introduction">

<t>JSON Template Language provides a mechanism for describing various parts of a template by using familiar syntax from Javascript and JSON. By using a familiar syntax we can get interoperability within the <eref target="https://tools.ietf.org/html/rfc7159, https://www.ecma-international.org/ecma-262/9.0/index.html#sec-template-literals">JSON</eref> and <eref target="https://tools.ietf.org/html/rfc6570">URI</eref> specifications.</t>

<t>The terms “string”, “object” and “array” are from the conventions of Javascript and JSON.</t>

<t>A JSON Template provides a structural description of a template, and when JSON is provided, machine-readable instructions on how to construct a string corresponding to those values. A template is transformed into a string by replacing each of the template literals with the corresponding JSON values.</t>

</section>
<section anchor="conventions-and-definitions" title="Conventions and Definitions">

<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="security-considerations" title="Security Considerations">
<t>When considering runtime security of JSON Template Language, the surface area is only expanding JSON value by key. No loops or operator grammar is defined and should be avoided in runtime contexts.</t>

</section>
<section anchor="iana-considerations" title="IANA Considerations">

<t>This document has no IANA actions.</t>

</section>
<section anchor="example-usage" title="Example Usage">
<t>for the given JSON:</t>

<figure><artwork type="JSON"><![CDATA[
{
  "query": {
    "number": 1,
    "salad": "potato"
  }
}
]]></artwork></figure>

<t>and the given template:</t>

<figure><artwork><![CDATA[
number${query.number}salad${query.salad}
        \__________/       \__________/
             |                   |
             |                   |
For each key in given JSON, substitute it by key into the string.
]]></artwork></figure>

<t>expansion:</t>

<figure><artwork><![CDATA[
number1saladpotato
]]></artwork></figure>

<section anchor="accessing-array-indicies" title="Accessing Array indicies">

<t>for the given JSON</t>

<figure><artwork type="JSON"><![CDATA[
{
  "query": {
    "numbers": [0, 1, 2, 3],
    "salads": ["caesar", "potato"]
  }
}
]]></artwork></figure>

<t>and the given template:</t>

<figure><artwork><![CDATA[
number${query.numbers[1]}salad${query.salads[1]}
        \_____________/         \_____________/
              |                        |
              |                        |
For each key in given JSON, substitute it by array index into the string.
]]></artwork></figure>

<t>expansion:</t>

<figure><artwork><![CDATA[
number1saladpotato
]]></artwork></figure>

</section>
<section anchor="accessing-nested-objects-and-arrays" title="Accessing Nested Objects and Arrays">

<t>for the given JSON</t>

<figure><artwork type="JSON"><![CDATA[
{
  "nested": {
    "query": {
      "number": 1,
      "salads": ["caesar", "potato"]
    }
  }
}
]]></artwork></figure>

<t>and the given template:</t>

<figure><artwork><![CDATA[
number${query.numbers[1]}salad${query.salads[1]}
        \_____________/         \_____________/
              |                        |
              |                        |
  For each key in given JSON, substitute it by path first. then array index into the string.
]]></artwork></figure>

<t>expansion:</t>

<figure><artwork><![CDATA[
number1saladpotato
]]></artwork></figure>

</section>
</section>
<section anchor="json-template-grammar" title="JSON Template Grammar">

<t>Language Grammar defined in <eref target="https://tools.ietf.org/html/rfc5234">ABNF</eref></t>

<figure><artwork type="abnf" name="syntax"><![CDATA[
grammar = *( [head] template-head identifier *["." path] *[array-left array-index array-right] template-tail [tail] )
template-head = "${"
template-tail = "}"
identifier = *( ALPHA / "_" )
path = *( ALPHA / "_" )
array-left = "["
array-right = "]"
array-index = *( DIGIT )
head = *( ALPHA /  DIGIT / special-characters )
tail = *( ALPHA / DIGIT / special-characters )
special-characters =  *("-" / "_" / "~" / "." / ":" / "/" / "?" / "#" / "[" / "]" / "@" /  "!" /  "&" / "'" / "(" / ")" /  "*" / "+" / "," / ";" / "=")
]]></artwork></figure>

<section anchor="template-literal" title="Template literal">
<t>The contents within the Template literal should be valid a key-value object mapping or array-index mapping for <eref target="https://tools.ietf.org/html/rfc7159">JSON</eref>.</t>

<figure><artwork type="abnf"><![CDATA[
grammar = *( [head] template-head identifier *["." path] \
[array-left array-index array-right] template-tail [tail] )
]]></artwork></figure>

<t>A template literal is represented within a <eref target="https://tools.ietf.org/html/rfc3986">URIs</eref> as a pair of curly braces starting with a <spanx style="verb">$</spanx>.</t>

<figure><artwork type="abnf"><![CDATA[
template-head = "${"
template-tail = "}"
]]></artwork></figure>

</section>
<section anchor="identifier" title="Identifier">
<t>An identifier is a valid JSON key.</t>

<figure><artwork type="abnf"><![CDATA[
identifier = *( ALPHA / "_" )
]]></artwork></figure>

</section>
<section anchor="path" title="Path">
<t>MUST be a valid nested JSON key that will be resolved with the identifier.</t>

<figure><artwork type="abnf"><![CDATA[
*["." path]
]]></artwork></figure>

</section>
<section anchor="array-index" title="Array Index">
<t>MUST be a valid index of a JSON array are represented within square brackets and MUST be a valid number.</t>

<figure><artwork type="abnf"><![CDATA[
*[array-left array-index array-right]
array-left = "["
array-right = "]"
array-index = *( DIGIT )
]]></artwork></figure>

</section>
<section anchor="head" title="Head">
<t>Head represents the characters before template-head, this could be beginning of the template or the last tail.</t>

<figure><artwork type="abnf"><![CDATA[
head = *( ALPHA /  DIGIT / special-characters )
]]></artwork></figure>

</section>
<section anchor="tail" title="Tail">
<t>Head represents the characters after the template-tail until the end of the template or the next instance of a template literal.</t>

<figure><artwork type="abnf"><![CDATA[
tail = *( ALPHA / DIGIT / special-characters )
]]></artwork></figure>

</section>
</section>


  </middle>

  <back>

    <references title='Normative References'>





<reference  anchor="RFC2119" target='https://www.rfc-editor.org/info/rfc2119'>
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials='S.' surname='Bradner' fullname='S. Bradner'><organization /></author>
<date year='1997' month='March' />
<abstract><t>In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized. This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t></abstract>
</front>
<seriesInfo name='BCP' value='14'/>
<seriesInfo name='RFC' value='2119'/>
<seriesInfo name='DOI' value='10.17487/RFC2119'/>
</reference>



<reference  anchor="RFC8174" target='https://www.rfc-editor.org/info/rfc8174'>
<front>
<title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
<author initials='B.' surname='Leiba' fullname='B. Leiba'><organization /></author>
<date year='2017' month='May' />
<abstract><t>RFC 2119 specifies common key words that may be used in protocol  specifications.  This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the  defined special meanings.</t></abstract>
</front>
<seriesInfo name='BCP' value='14'/>
<seriesInfo name='RFC' value='8174'/>
<seriesInfo name='DOI' value='10.17487/RFC8174'/>
</reference>




    </references>




  </back>

<!-- ##markdown-source:
H4sIACYJn1wAA91Y23LbOBJ951dg6NRunBUl27mNteXaUWwnUcq3ie3a2tK4
MhAJSUxIUANAtrUe5dvndIOUKFmbOJU8rR4gEAQa3X36yiiKApe6TLXFu/PT
E3Gh8nEmnRJHUg8ncqgC2e8bdb3y2gZJEWuZ41hi5MBFHwstbfTRFjpy5Z4o
q0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