Internet Engineering Task Force | A. Boronine, Ed. |
Internet-Draft | |
Intended status: Informational | November 9, 2014 |
Expires: May 13, 2015 |
Minimal JSON Type System
draft-boronine-teleport-00
Teleport is a minimal type system designed as an extension of JSON. It comes with 10 types sufficient for basic use, but it defines a pattern for extending it with arbitrary types. Teleport's type definitions are JSON values, for example, an array of strings is defined as {"Array": "String"}.
Teleport implementations can be used for data serialization, input validation, for documenting JSON APIs and for building API clients.
This document provides the mathematical basis of Teleport and can be used for implementing libraries.
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 http://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 May 13, 2015.
Copyright (c) 2014 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 (http://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.
In Teleport, a type is a relation between a type definition and a value space. For example:
t("Integer") = {0, -1, 1, -2, 2, -3, 3, ...}
Here "Integer" is a type definition and t("Integer") is the set of all values this type can take. The t function is used to represent this relationship.
Because Teleport is based on JSON, all value spaces are sets of JSON values. More interestingly, type definitions are JSON values too, which makes it trivial to share them with other programs.
Teleport's design goals is to be a natural extension of JSON, be extremely lightweight, and extendable not only with rich types but with high-level type system concepts.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].
The terms "JSON", "JSON text", "JSON value", "member", "element", "object", "array", "number", "string", "boolean", "true", "false", and "null" in this document are to be interpreted as defined in RFC 4627 [RFC4627].
Throughout this document, an extended JSON syntax is used. Unquoted strings are symbols representing JSON values, sets and functions. Also, the following set theory syntax is used:
Types defined simply by a string, like "Integer" above, are called concrete. Teleport ships with 7 concrete types.
A generic type maps a set of schemas to a set of value spaces. Each pair in the mapping is called an instance. For example, {"Array": "Integer"} is an instance of the Array type.
Three generic types are provided: Array, Map and Struct. Their precise definition is provided in the following sections, but these examples should be enough to understand how they work:
["foo", "bar"] :: t({"Array": "String"}) {"a": 1, "b": 2} :: t({"Map": "Integer"}) {"name": "Alexei"} :: t({"Struct": { "required": {"name": "String"}, "optional": {"age": "Integer"}})
"Schema", one of the build-in concrete types, is defined as the set of all known type definitions. This is made possible by the fact that type definitions are JSON values. The Schema type is useful to specify APIs. For example, to describe a function you can use this:
t({"Struct": { "required": { "input": "Schema", "output": "Schema"}}}
The set of all JSON values is called V. A subset of V is called a value space and the set of all value spaces is called S.
There is a certain function t that maps JSON values to value spaces.
x is of concrete type c if and only if
x is of generic type g if and only if
x :: t({"Array": p}) if and only if
x :: t({"Map": p}) if and only if
x :: t({"Struct": p}) if and only if
This memo includes no request to IANA.
All drafts are required to have a security considerations section. See RFC 3552 [RFC3552] for a guide.
[ISO.8601.1988] | International Organization for Standardization, "Data elements and interchange formats - Information interchange - Representation of dates and times", ISO Standard 8601, June 1988. |
[RFC2119] | Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997. |
[RFC4627] | Crockford, D., "The application/json Media Type for JavaScript Object Notation (JSON)", RFC 4627, July 2006. |
[RFC3552] | Rescorla, E. and B. Korver, "Guidelines for Writing RFC Text on Security Considerations", BCP 72, RFC 3552, July 2003. |
Comments are solicited and should be addressed to the working group's mailing list at teleport-json@googlegroups.com and/or the author.