TOC 
Internet Engineering Task ForceG. Luff, Ed.
Internet-Draft 
Intended status: InformationalK. Zyp
Expires: July 24, 2013SitePen (USA)
 G. Court
 January 20, 2013


Hyperlinks and media for JSON Schema
draft-zyp-json-hyper-schema-04

Abstract

JSON Schema is a JSON based format for defining the structure of JSON data. This document specifies hyperlink- and hypermedia-related keywords for the JSON Schema format.

Status of This Memo

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 July 24, 2013.

Copyright Notice

Copyright (c) 2013 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.



Table of Contents

1.  Introduction
2.  Conventions and Terminology
3.  Overview
    3.1.  Design Considerations
4.  Schema keywords
    4.1.  links
        4.1.1.  Multiple links per URI
    4.2.  fragmentResolution
        4.2.1.  json-pointer fragment resolution
    4.3.  media
        4.3.1.  binaryEncoding
        4.3.2.  type
    4.4.  pathStart
5.  Link Description Object
    5.1.  href
        5.1.1.  URI Templating
    5.2.  rel
        5.2.1.  Fragment resolution with "root" links
        5.2.2.  Security Considerations for "self" links
    5.3.  targetSchema
        5.3.1.  Security Considerations for "targetSchema"
    5.4.  mediaType
        5.4.1.  Security concerns for "mediaType"
    5.5.  Submission Link Properties
        5.5.1.  method
        5.5.2.  encType
        5.5.3.  schema
6.  IANA Considerations
    6.1.  Registry of Link Relations
7.  References
    7.1.  Normative References
    7.2.  Informative References
Appendix A.  Change Log




 TOC 

1.  Introduction

JSON Schema is a JSON based format for defining the structure of JSON data. This document specifies hyperlink- and hypermedia-related keywords for the JSON Schema format.



 TOC 

2.  Conventions and Terminology

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 (Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels,” March 1997.) [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 (Crockford, D., “The application/json Media Type for JavaScript Object Notation (JSON),” July 2006.) [RFC4627].

The terms "schema", "instance", "property" and "item" are to be interpreted as defined in the JSON Schema core definition [FIXME_LINK].



 TOC 

3.  Overview

This document describes how JSON Schema can be used to define hyperlinks on instance data. It also defines how to provide additional information required to interpret JSON data as rich multimedia documents.

Just as with the core JSON schema keywords, all the properties described in the "Schema Keywords" section are optional.

Here is an example JSON Schema defining hyperlinks, and providing a multimedia interpretation for the "imgData" property:


{
    "title": "Written Article",
    "type": "object",
    "properties": {
        "id": {
            "title": "Article Identifier",
            "type": "number"
        },
        "title": {
            "title": "Article Title",
            "type": "string"
        },
        "authorId": {
            "type": "integer"
        },
        "imgData": {
            "title": "Article Illustration (small)",
            "type": "string",
            "media": {
                "binaryEncoding": "base64",
                "type": "image/png"
            }
        }
    },
    "required" : ["id", "title", "authorId"],
    "links": [
        {
            "rel": "full",
            "href": "{id}"
        },
        {
            "rel": "author",
            "href": "/user?id={authorId}"
        }
    ]
}

This example schema defines the properties of the instance. For the "imgData" property, it specifies that that it should be base64-decoded and the resulting binary data treated as a PNG image. It also defines link relations for the instance, with URIs incorporating values from the instance.

An example of data following the above schema might be:


{
    "id": 15,
    "title": "Example data",
    "authorId": 105,
    "imgData": "iVBORw...kJggg=="
}

The base-64 data has been abbreviated for readability.



 TOC 

3.1.  Design Considerations

The purpose of this document is to define keywords for the JSON Schema that allow JSON data to be understood as hyper-text.

JSON data on its own requires special knowledge from the client about the format in order to be interpretable as hyper-text. This document proposes a way to describe the hyper-text and hyper-media interpretation of such JSON formats, without defining reserved keywords or otherwise restricting the structure of the JSON data.



 TOC 

4.  Schema keywords

The following properties are defined for JSON Schema objects:



 TOC 

4.1.  links

The property of schemas is used to associate Link Description Objects with instances. The value of this property MUST be an array, and the items in the array must be Link Description Objects, as defined below.

An example schema using the "links" keywords could be:

{
    "title": "Schema defining links",
    "links": [
        {
            "rel": "full",
            "href": "{id}"
        },
        {
            "rel": "parent",
            "href": "{parent}"
        }
    ]
}


 TOC 

4.1.1.  Multiple links per URI

A single URI might have more than one role with relation to an instance. This is not a problem - the same URI can be used in more than one Link Description Object.

For example, this schema describes a format for news posts, accessed via HTTP. The links describe how to access the comments for a news post, how to search the comments, and how to submit new comments, all with the same URI:

{
    "title": "News post",
    ...
    "links": [
        {
            "rel": "comments",
            "href": "/{id}/comments"
        },
        {
            "rel": "search",
            "href": "/{id}/comments",
            "schema": {
                "type": "object",
                "properties": {
                    "searchTerm": {
                        "type": "string"
                    },
                    "itemsPerPage": {
                        "type": "integer",
                        "minimum": 10,
                        "multipleOf": 10,
                        "default": 20
                    }
                },
                "required": ["searchTerm"]
            }
        },
        {
            "rel": "post-comment",
            "href": "/{id}/comments",
            "method": "POST",
            "schema": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string"
                    }
                },
                "required": ["message"]
            }
        }
    ]
}

If the client follows the first link, the URI might be expanded to "/15/comments". For the second link, the method is "GET" (the default for HTTP) so the parameters are added to the URL to produce something like: "/15/comments?searchTerm=JSON&itemsPerPage=50". The third link might have a URI of "/15/comments", but the text content of the new comment is posted as JSON.



 TOC 

4.2.  fragmentResolution

This property indicates the fragment resolution protocol to use for resolving fragment identifiers in URIs within the instance representations. This applies to the instance object URIs and all children of the instance object's URIs. The default fragment resolution protocol is "json-pointer", which is defined below. Other fragment resolution protocols MAY be used, but are not defined in this document.

The fragment identifier is based on RFC 3986, Sec 5 (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) [RFC3986], and defines the mechanism for resolving references to entities within a document.

Note that if the instance is described by a schema providing the a link with "root" relation, or such a link is provided in using the HTTP Link header, then all fragment resolution should be resolved relative to the target of the root link. The only exception to this is the resolution of "root" links themselves.



 TOC 

4.2.1.  json-pointer fragment resolution

The "json-pointer" fragment resolution protocol uses a JSON Pointer (Bryan, P. and K. Zyp, “JSON Pointer,” October 2011.) [json‑pointer] to resolve fragment identifiers in URIs within instance representations.



 TOC 

4.3.  media

The value of this properties MUST be an object. It MAY contain any of the following properties:



 TOC 

4.3.1.  binaryEncoding

The value of this property SHOULD be ignored for any instance that is not a string. If the instance value is a string, this property defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this property. RFC 2045, Sec 6.1 (Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies,” November 1996.) [RFC2045] lists the possible values for this property.



 TOC 

4.3.2.  type

The value of this property must be a media type RFC 2046 (Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types,” November 1996.) [RFC2046]. This property defines the media type of instances which this schema defines.

If the "binaryEncoding" property is not set, but the instance value is a string, then the value of this property SHOULD specify a text document type, and the character set SHOULD be considered to be the character encoding of the JSON document itself (for which the default is UTF-8).

For example:


{
    "type": "string",
    "media": {
        "binaryEncoding": "base64",
        "type": "image/png"
    }
}

Instances described by this schema should be strings, and their values should be interpretable as base64-encoded PNG images.

Another example:


{
    "type": "string",
    "media": {
        "mediaType": "text/html"
    }
}

Instances described by this schema should be strings containing HTML, using the UTF-8 character set.



 TOC 

4.4.  pathStart

This property is a URI that defines what the instance's URI MUST start with in order to validate. The value of the "pathStart" property MUST be resolved relative to the closest URI Resolution Scope (as defined in the core specification [FIXME link]), using the rules from RFC 3986, Sec 5 (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) [RFC3986].

When multiple schemas have been referenced for an instance, the user agent can determine if this schema is applicable for a particular instance by determining if the URI of the instance begins with the the value of the "pathStart" property. If the URI of the instance does not start with this URI, or if another schema specifies a starting URI that is longer and also matches the instance, this schema SHOULD NOT be considered to describe the instance. Any schema that does not have a pathStart property SHOULD be considered applicable to all the instances for which it is referenced.



 TOC 

5.  Link Description Object

A Link Description Object (LDO) is used to describe a single link relation. In the context of a schema, it defines the link relations of the instances of the schema, and can be parameterized by the instance values. A Link Description Object (LDO) must be an object.

The link description format can be used without JSON Schema, and use of this format can be declared by referencing the normative link description schema as the schema for the data structure that uses the links. The URI of the normative link description schema is: http://json-schema.org/links (latest version) or http://json-schema.org/draft-04/links (draft-04 version).

"Form"-like functionality can be defined by use of the "schema" keyword, which supplies a schema describing the data to supply to the server.



 TOC 

5.1.  href

The value of the "href" link description property is a template used to determine the target URI of the related resource. The value of the instance property SHOULD be resolved as a URI-Reference per RFC 3986 (Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005.) [RFC3986] and MAY be a relative reference to a URI. The base URI to be used for relative URI resolution SHOULD be the URI used to retrieve the instance object (not the schema).

The base URI to be used for relative URI resolution SHOULD is defined as follows:

if the data has a link defined, with a relation of "self", then the \"href\" value of that link is used

if no such link exists, the URI should be resolved against the link with relation "self" belonging to the closest parent node in the JSON document

if no such links exist (the data and all its parents in the tree do not have a "self" link), the URI used to fetch the document should be used.

This property is not optional.



 TOC 

5.1.1.  URI Templating

The value of "href" is to be used as a URI Template, as defined in RFC 6570 (Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., and D. Orchard, “URI Template,” March 2012.) [RFC6570]. However, some special considerations apply:



 TOC 

5.1.1.1.  Pre-processing

The URI Template specification (Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., and D. Orchard, “URI Template,” March 2012.) [RFC6570] has a very restrictive set of characters available for variable names. Property names in JSON, however, can be any UTF-8 string. As such, the following pre-processing rules apply:



 TOC 

5.1.1.1.1.  Bracket escaping

For any text that is:

Surrounded by a pair of rounded brackets: ( )

The closing rounded bracket is not immediately followed by another closing bracket

The closing rounded bracket is not immediately preceded by an odd number of closing brackets

The surrounding rounded brackets are themselves contained within a pair of curly brackets: { }

Before using "href" as a template, that section of the text MUST be replaced, according to the following rules:

If the brackets contained no text (the empty string), then they MUST be replaced with "%65mpty" (which is "empty" with a percent-encoded "e")

Otherwise:

the text MUST have all pairs of close-brackets "))" replaced with a single close bracket

the text MUST then be replaced with its percent-encoded equivalent, such that the result is a valid RFC 6570 variable name (note that this includes encoding characters such as "*" and "!")



 TOC 

5.1.1.1.2.  Replacing $

After the above substitutions, if the character "$" (dollar sign) appears within a pair of curly brackets, then it MUST be replaced with the text "%73elf" (which is "self" with a percent-encoded "s").



 TOC 

5.1.1.1.3.  Examples

For example, here are some possible values for "href", followed by the results after pre-processing:


Input                    Output
-----------------------------------------
"no change"              "no change"
"(no change)"            "(no change)"
"{(escape space)}"       "{escape%20space}"
"{(escape+plus)}"        "{escape%2Bplus}"
"{(escape*asterisk)}"    "{escape%2Aasterisk}"
"{(escape(bracket)}"     "{escape%28bracket}"
"{(escape))bracket)}"    "{escape%29bracket}"
"{(a (b)))}"             "{a%20%28b%29}
"{()}"                   "{%65mpty}
"{+$*}"                   "{+%73elf*}
"{+($)*}"                 "{+%24*}

Note that in the final example, because the "+" was outside the brackets, it remained unescaped, whereas in the fourth example the "+" was escaped.



 TOC 

5.1.1.2.  Values for substitution

After pre-processing, the template is filled out using data from the instance. For a given variable name, the value to use is determined as follows:

If the variable name is "%73elf", then the instance value itself MUST be used.

If the variable name is "%65mpty", then the instances's empty-string ("") property MUST be used (if it exists).

If the instance is an array, and the variable name is a representation of a positive integer, then the value at the corresponding array index MUST be used (if it exists).

Otherwise, the variable name should be percent-decoded, and the corresponding object property MUST be used (if it exists).



 TOC 

5.1.1.2.1.  Converting to strings

When any value referenced by the URI template is null, a boolean or a number, then it should first be converted into a string as follows:

null values SHOULD be replaced by the text "null"

boolean values SHOULD be replaced by their lower-case equivalents: "true" or "false"

numbers SHOULD be replaced with their original JSON representation.

In some software environments the original JSON representation of a number will not be available (there is no way to tell the difference between 1.0 and 1), so any reasonable representation should be used. Schema and API authors should bear this in mind, and use other types (such as string or boolean) if the exact representation is important.



 TOC 

5.1.1.3.  Missing values

Sometimes, the appropriate values will not be available. For example, the template might specify the use of object properties, but the instance is an array or a string.

If any of the values required for the template are not present in the JSON instance, then substitute values MAY be provided from another source (such as default values). Otherwise, the link definition SHOULD be considered not to apply to the instance.



 TOC 

5.2.  rel

The value of the "rel" property indicates the name of the relation to the target resource. This property is not optional.

The relation to the target SHOULD be interpreted as specifically from the instance object that the schema (or sub-schema) applies to, not just the top level resource that contains the object within its hierarchy. A link relation from the top level resource to a target MUST be indicated with the schema describing the top level JSON representation.

Relationship definitions SHOULD NOT be media type dependent, and users are encouraged to utilize existing accepted relation definitions, including those in existing relation registries (see RFC 4287 (Nottingham, M., Ed. and R. Sayre, Ed., “The Atom Syndication Format,” December 2005.) [RFC4287]). However, we define these relations here for clarity of normative interpretation within the context of JSON Schema defined relations:

self
If the relation value is "self", when this property is encountered in the instance object, the object represents a resource and the instance object is treated as a full representation of the target resource identified by the specified URI.
full
This indicates that the target of the link is the full representation for the instance object. The instance that contains this link may not be the full representation.
describedBy
This indicates the target of the link is a schema describing the instance object. This MAY be used to specifically denote the schemas of objects within a JSON object hierarchy, facilitating polymorphic type data structures.
root
This relation indicates that the target of the link SHOULD be treated as the root or the body of the representation for the purposes of user agent interaction or fragment resolution. All other properties of the instance objects can be regarded as meta-data descriptions for the data. The URI of this link MUST be a fragment, specifying a location within the instance. If it is not, this link should be ignored.

The following relations are applicable for schemas (the schema as the "from" resource in the relation):

instances
This indicates the target resource that represents a collection of instances of a schema.
create
This indicates a target to use for creating new instances of a schema. This link definition SHOULD be a submission link with a non-safe method (like POST).

Links defined in the schema using these relation values SHOULD not require parameterization with data from the instance, as they describe a link for the schema, not the instances.

For example, if a schema is defined:

{
    "links": [{
        "rel": "self",
        "href": "{id}"
    }, {
        "rel": "up",
        "href": "{upId}"
    }, {
        "rel": "children",
        "href": "?upId={id}"
    }]
}

And if a collection of instance resources were retrieved with JSON representation:

GET /Resource/

[{
    "id": "thing",
    "upId": "parent"
}, {
    "id": "thing2",
    "upId": "parent"
}]

This would indicate that for the first item in the collection, its own (self) URI would resolve to "/Resource/thing" and the first item's "up" relation SHOULD be resolved to the resource at "/Resource/parent". The "children" collection would be located at "/Resource/?upId=thing".

Note that these relationship values are case-insensitive, consistent with their use in HTML and the HTTP Link header (Nottingham, M., “Web Linking,” May 2010.) [I‑D.nottingham‑http‑link‑header].



 TOC 

5.2.1.  Fragment resolution with "root" links

The presence of a link with relation "root" alters what the root of the document is considered to be.

For example, say we have the following schema:

{
    "links": [{
        "rel": "root",
        "href": "#/myRootData"
    }]
}

And the following data, returned from the URI: "http://example.com/data/12345":

{
    "myRootData": {
        "title": "Document title"
    },
    "metaData": {
        ...
    }
}

To correctly resolve the URL "http://example.com/data/12345", we must take the "root" link into account. Here are some example URIs, along with the data they would resolve to:


URI                                         Data
-----------------------------------------------------------------------
http://example.com/data/12345               {"title": "Document title"}
http://example.com/data/12345#/title        "Document title"



 TOC 

5.2.1.1.  Preventing the URI resolution paradox

Because of the "root" link type's effect on URL resolution, it possible to create apparent paradoxes in URI resolution. For example, consider this response from a server:


Content-Type: application/json; profile=#/schema

{
    "myRootData": {
        "title": "Document title"
    },
    "schema": {
        "type": "object",
        "properties": {
            "root": {
                "title": "Document",
                "type": "object",
                "properties": {
                    "title": {"type": "string"}
                }
            }
        },
        "links": [
            {
                "rel": "root",
                "href": "#/myRootData"
            }
        ]
    }
}

The "profile" parameter in the "Content-Type" HTTP header defines the schema to be inside the data itself. But the schema defines a "root" link, which changes the document root, which seems like it should change the target of "#/schema".

To avoid this scenario, the following behaviour is defined: when resolving URIs for schemas, that schema MUST NOT be taken into account when calculating the document root.



 TOC 

5.2.2.  Security Considerations for "self" links

When link relation of "self" is used to denote a full representation of an object, the user agent SHOULD NOT consider the representation to be the authoritative representation of the resource denoted by the target URI if the target URI is not equivalent to or a sub-path of the the URI used to request the resource representation which contains the target URI with the "self" link.

For example, if a hyper schema was defined:

{
    "links": [{
        "rel": "self",
        "href": "{id}"
    }]
}

And a resource was requested from somesite.com:


GET /foo/

With a response of:

Content-Type: application/json; profile=/schema-for-this-data

[{
    "id": "bar",
    "name": "This representation can be safely treated \
        as authoritative "
}, {
    "id": "/baz",
    "name": "This representation should not be treated as \
        authoritative the user agent should make request the resource\
        from '/baz' to ensure it has the authoritative representation"
}, {
    "id": "http://othersite.com/something",
    "name": "This representation\
        should also not be treated as authoritative and the target\
        resource representation should be retrieved for the\
        authoritative representation"
}]


 TOC 

5.3.  targetSchema

This property value is advisory only, and is a schema that defines the expected structure of the JSON representation of the target of the link, if the target of the link is returned using JSON representation.



 TOC 

5.3.1.  Security Considerations for "targetSchema"

This property has similar security concerns to that of "mediaType". Clients MUST NOT use the value of this property to aid in the interpretation of the data received in response to following the link, as this leaves "safe" data open to re-interpretation.

For example, suppose two programmers are having a discussion about web security using a text-only message board. Here is some data from that conversation, with a URI of: http://forum.example.com/topics/152/comments/13

{
    "topicId": 152,
    "commentId": 13,
    "from": {
        "name": "Jane",
        "id": 5
    },
    "to": {
        "name": "Jason",
        "id": 8
    },
    "message": "It's easy, you just add some HTML like this: <script>doSomethingEvil()</script>"
}

A third party might then write provide the following Link Description Object at another location:

{
    "rel": "evil-attack",
    "href": "http://forum.example.com/topics/152/comments/13",
    "targetSchema": {
        "properties": {
            "message": {
                "description": "Re-interpret the message text as HTML",
                "media": {
                    "type": "text/html"
                }
            }
        }
    }
}

If the client used this "targetSchema" value when interpreting the above data, then it might display the contents of "message" as HTML. At this point, the JavaScript embedded in the message might be executed (in the context of the "forum.example.com" domain).



 TOC 

5.4.  mediaType

The value of this property is advisory only, and represents the media type RFC 2046 (Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types,” November 1996.) [RFC2046], that is expected to be returned when fetching this resource. This property value MAY be a media range instead, using the same pattern defined in RFC 2161, section 14.1 - HTTP "Accept" header (Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, “Hypertext Transfer Protocol -- HTTP/1.1,” June 1999.) [RFC2616].

This property is analogous to the "type" property of elements in HTML 4.01 (advisory content type), or the "type" parameter in the HTTP Link header (Nottingham, M., “Web Linking,” May 2010.) [I‑D.nottingham‑http‑link‑header]. User agents MAY use this information to inform the interface they present to the user before the link is followed, but this information MUST NOT use this information in the interpretation of the resulting data. When deciding how to interpret data obtained through following this link, the behaviour of user agents MUST be identical regardless of the value of the this property.

If this property's value is specified, and the link's target is to be obtained using any protocol that supports the HTTP/1.1 "Accept" header RFC 2616, section 14.1 (Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, “Hypertext Transfer Protocol -- HTTP/1.1,” June 1999.) [RFC2616], then user agents MAY use the value of this property to aid in the assembly of that header when making the request to the server.

If this property's value is not specified, then the value should be taken to be "application/json".

For example, if a schema is defined:


{
    "links": [{
        "rel": "self",
        "href": "/{id}/json"
    }, {
        "rel": "alternate",
        "href": "/{id}/html",
        "mediaType": "text/html"
    }, {
        "rel": "alternate",
        "href": "/{id}/rss",
        "mediaType": "application/rss+xml"
    }, {
        "rel": "icon",
        "href": "{id}/icon",
        "mediaType": "image/*"
    }]
}

A suitable instance described by this schema would have four links defined. The link with a "rel" value of "self" would have an expected MIME type of "application/json" (the default). The two links with a "rel" value of "alternate" specify the locations of HTML and RSS versions of the current item. The link with a "rel" value of "icon" links to an image, but does not specify the exact format.

A visual user agent displaying the item from the above example might present a button representing an RSS feed, which when pressed passes the target URI (calculated "href" value) to an view more suited to displaying it, such as a news feed aggregator tab.

Note that presenting the link in the above manner, or passing the URI to a news feed aggregator view does not constitute interpretation of the data, but an interpretation of the link. The interpretation of the data itself is performed by the news feed aggregator, which SHOULD reject any data that would not have also been interpreted as a news feed, had it been displayed in the main view.



 TOC 

5.4.1.  Security concerns for "mediaType"

The "mediaType" property in link definitions defines the expected format of the link's target. However, this is advisory only, and MUST NOT be considered authoritative.

When choosing how to interpret data, the type information provided by the server (or inferred from the filename, or any other usual method) MUST be the only consideration, and the "mediaType" property of the link MUST NOT be used. User agents MAY use this information to determine how they represent the link or where to display it (for example hover-text, opening in a new tab). If user agents decide to pass the link to an external program, they SHOULD first verify that the data is of a type that would normally be passed to that external program.

This is to guard against re-interpretation of "safe" data, similar to the precautions for "targetSchema".



 TOC 

5.5.  Submission Link Properties

The following properties also apply to link definition objects, and provide functionality analogous to HTML forms, in providing a means for submitting extra (often user supplied) information to send to a server.



 TOC 

5.5.1.  method

This property defines which method can be used to access the target resource. In an HTTP environment, this could be "GET" or "POST" (other HTTP methods such as "PUT" and "DELETE" have semantics that are clearly implied by accessed resources, and do not need to be defined here). This defaults to "GET".



 TOC 

5.5.2.  encType

If present, this property indicates a query media type format that the server supports for querying or posting to the collection of instances at the target resource. The query can be suffixed to the target URI to query the collection with property-based constraints on the resources that SHOULD be returned from the server or used to post data to the resource (depending on the method).

For example, with the following schema:

{
    "links": [{
        "encType": "application/x-www-form-urlencoded",
        "method": "GET",
        "href": "/Product/",
        "properties": {
            "name": {
                "description": "name of the product"
            }
        }
    }]
}

This indicates that the client can query the server for instances that have a specific name.

For example:


/Product/?name=Slinky

If no encType or method is specified, only the single URI specified by the href property is defined. If the method is POST, "application/json" is the default media type.

 TOC 

5.5.3.  schema

This property contains a schema which defines the acceptable structure of the submitted request. For a GET request, this schema would define the properties for the query string and for a POST request, this would define the body.

Note that this is separate from the URI templating of "href" (which uses data from the instance, not submitted by the user). It is also separate from the "targetSchema" property, which provides a schema for the data that the client should expect to be returned when they follow the link.



 TOC 

6.  IANA Considerations

The proposed MIME media type for JSON Schema is "application/schema+json".

Type name: application

Subtype name: schema+json

Required parameters: profile

The value of the profile parameter SHOULD be a URI (relative or absolute) that refers to the schema used to define the structure of this structure (the meta-schema). Normally the value would be http://json-schema.org/draft-04/hyper-schema, but it is allowable to use other schemas that extend the hyper schema's meta-schema.

Optional parameters: pretty

The value of the pretty parameter MAY be true or false to indicate if additional whitespace has been included to make the JSON representation easier to read.



 TOC 

6.1.  Registry of Link Relations

This registry is maintained by IANA per RFC 4287 (Nottingham, M., Ed. and R. Sayre, Ed., “The Atom Syndication Format,” December 2005.) [RFC4287] and this specification adds four values: "full", "create", "instances", "root". New assignments are subject to IESG Approval, as outlined in RFC 5226 (Narten, T. and H. Alvestrand, “Guidelines for Writing an IANA Considerations Section in RFCs,” May 2008.) [RFC5226]. Requests should be made by email to IANA, which will then forward the request to the IESG, requesting approval.



 TOC 

7.  References



 TOC 

7.1. Normative References

[RFC2045] Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies,” RFC 2045, November 1996 (TXT).
[RFC2119] Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels,” BCP 14, RFC 2119, March 1997 (TXT, HTML, XML).
[RFC3339] Klyne, G., Ed. and C. Newman, “Date and Time on the Internet: Timestamps,” RFC 3339, July 2002 (TXT, HTML, XML).
[RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” STD 66, RFC 3986, January 2005 (TXT, HTML, XML).
[RFC4287] Nottingham, M., Ed. and R. Sayre, Ed., “The Atom Syndication Format,” RFC 4287, December 2005 (TXT, HTML, XML).
[RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., and D. Orchard, “URI Template,” RFC 6570, March 2012 (TXT).
[json-pointer] Bryan, P. and K. Zyp, “JSON Pointer,” October 2011.


 TOC 

7.2. Informative References

[RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, “Hypertext Transfer Protocol -- HTTP/1.1,” RFC 2616, June 1999 (TXT, PS, PDF, HTML, XML).
[RFC4627] Crockford, D., “The application/json Media Type for JavaScript Object Notation (JSON),” RFC 4627, July 2006 (TXT).
[RFC5226] Narten, T. and H. Alvestrand, “Guidelines for Writing an IANA Considerations Section in RFCs,” BCP 26, RFC 5226, May 2008 (TXT).
[RFC2046] Freed, N. and N. Borenstein, “Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types,” RFC 2046, November 1996 (TXT).
[I-D.hammer-discovery] Hammer-Lahav, E., “LRDD: Link-based Resource Descriptor Discovery,” draft-hammer-discovery-06 (work in progress), May 2010 (TXT).
[I-D.nottingham-http-link-header] Nottingham, M., “Web Linking,” draft-nottingham-http-link-header-10 (work in progress), May 2010 (TXT).
[W3C.REC-html401-19991224] Hors, A., Raggett, D., and I. Jacobs, “HTML 4.01 Specification,” World Wide Web Consortium Recommendation REC-html401-19991224, December 1999 (HTML).
[W3C.CR-CSS21-20070719] Hickson, I., Lie, H., Çelik, T., and B. Bos, “Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification,” World Wide Web Consortium CR CR-CSS21-20070719, July 2007 (HTML).


 TOC 

Appendix A.  Change Log

draft-04
  • Split hyper-schema definition out from main schema.
  • Removed "readonly"
  • Capitalised the T in "encType"
  • Moved "mediaType" and "contentEncoding" to the new "media" property (renamed "type" and "binaryEncoding")
  • Added "mediaType" property to LDOs
  • Replaced "slash-delimited" fragment resolution with "json-pointer".
  • Added "template" LDO attribute.
  • Improved wording of sections.
draft-03
  • Added example and verbiage to "extends" attribute.
  • Defined slash-delimited to use a leading slash.
  • Made "root" a relation instead of an attribute.
  • Removed address values, and MIME media type from format to reduce confusion (mediaType already exists, so it can be used for MIME types).
  • Added more explanation of nullability.
  • Removed "alternate" attribute.
  • Upper cased many normative usages of must, may, and should.
  • Replaced the link submission "properties" attribute to "schema" attribute.
  • Replaced "optional" attribute with "required" attribute.
  • Replaced "maximumCanEqual" attribute with "exclusiveMaximum" attribute.
  • Replaced "minimumCanEqual" attribute with "exclusiveMinimum" attribute.
  • Replaced "requires" attribute with "dependencies" attribute.
  • Moved "contentEncoding" attribute to hyper schema.
  • Added "additionalItems" attribute.
  • Added "id" attribute.
  • Switched self-referencing variable substitution from "-this" to "@" to align with reserved characters in URI template.
  • Added "patternProperties" attribute.
  • Schema URIs are now namespace versioned.
  • Added "$ref" and "$schema" attributes.
draft-02
  • Replaced "maxDecimal" attribute with "divisibleBy" attribute.
  • Added slash-delimited fragment resolution protocol and made it the default.
  • Added language about using links outside of schemas by referencing its normative URI.
  • Added "uniqueItems" attribute.
  • Added "targetSchema" attribute to link description object.
draft-01
  • Fixed category and updates from template.
draft-00
  • Initial draft.



 TOC 

Authors' Addresses

  Geraint Luff (editor)
  Cambridge
  UK
EMail:  luffgd@gmail.com
  
  Kris Zyp
  SitePen (USA)
  530 Lytton Avenue
  Palo Alto, CA 94301
  USA
Phone:  +1 650 968 8787
EMail:  kris@sitepen.com
  
  Gary Court
  Calgary, AB
  Canada
EMail:  gary.court@gmail.com