Network Working Group | S. Jonas |
Internet-Draft | ETC Labs Core |
Intended status: Informational | March 29, 2019 |
Expires: September 30, 2019 |
JSON Template Language
draft-jonas-json-template-language-01
JSON Template Language is a simple, compact template language to substitute JSON into a template. It is derived from the template literals of Javascript, as defined in the ECMAScript Programming Language Standard, Ninth Edition ECMA-262. It has uses not limited to: specifying interfaces, runtime expression mapping, and other forms of programmatically interacting with JSON and templates.
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 https://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 September 30, 2019.
Copyright (c) 2019 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 (https://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.
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 JSON and URI specifications.
The terms “string”, “object” and “array” are from the conventions of Javascript and JSON.
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.
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 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
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.
This document has no IANA actions.
for the given JSON:
{ "query": { "number": 1, "salad": "potato" } }
and the given template:
number${query.number}salad${query.salad} \__________/ \__________/ | | | | For each key in given JSON, substitute it by key into the string.
expansion:
number1saladpotato
for the given JSON
{ "query": { "numbers": [0, 1, 2, 3], "salads": ["caesar", "potato"] } }
and the given template:
number${query.numbers[1]}salad${query.salads[1]} \_____________/ \_____________/ | | | | For each key in given JSON, substitute it by array index into the string.
expansion:
number1saladpotato
for the given JSON
{ "nested": { "query": { "number": 1, "salads": ["caesar", "potato"] } } }
and the given template:
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.
expansion:
number1saladpotato
Language Grammar defined in ABNF
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 = *("-" / "_" / "~" / "." / ":" / "/" / "?" / "#" / "[" / "]" / "@" / "!" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=")
The contents within the Template literal should be valid a key-value object mapping or array-index mapping for JSON.
grammar = *( [head] template-head identifier *["." path] \ [array-left array-index array-right] template-tail [tail] )
A template literal is represented within a URIs as a pair of curly braces starting with a $.
template-head = "${" template-tail = "}"
An identifier is a valid JSON key.
identifier = *( ALPHA / "_" )
MUST be a valid nested JSON key that will be resolved with the identifier.
*["." path]
MUST be a valid index of a JSON array are represented within square brackets and MUST be a valid number.
*[array-left array-index array-right] array-left = "[" array-right = "]" array-index = *( DIGIT )
Head represents the characters before template-head, this could be beginning of the template or the last tail.
head = *( ALPHA / DIGIT / special-characters )
Tail represents the characters after the template-tail until the end of the template or the next instance of a template literal.
tail = *( ALPHA / DIGIT / special-characters )
[RFC2119] | Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997. |
[RFC8174] | Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017. |