One document matched: draft-fge-json-schema-validation-00.xml


<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY RFC1034 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.1034.xml">
<!ENTITY RFC2119 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2373 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2373.xml">
<!ENTITY RFC2673 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2673.xml">
<!ENTITY RFC3339 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml">
<!ENTITY RFC3986 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
<!ENTITY RFC4627 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4627.xml">
<!ENTITY RFC5322 SYSTEM "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5322.xml">
]>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc strict="no"?>
<?rfc rfcedstyle="yes"?>
<rfc category="info" docName="draft-fge-json-schema-validation-00" ipr="trust200902">
    <front>
        <title abbrev="JSON Schema">JSON Schema: interactive and non interactive validation</title>

        <author fullname="Francis Galiegue" initials="fge" surname="Galiegue" role="editor">
            <address>
                <email>fgaliegue@gmail.com</email>
            </address>
        </author>

        <author fullname="Kris Zyp" initials="K" surname="Zyp">
            <organization>SitePen (USA)</organization>
            <address>
                <postal>
                    <street>530 Lytton Avenue</street>
                    <city>Palo Alto, CA 94301</city>
                    <country>USA</country>
                </postal>
                <phone>+1 650 968 8787</phone>
                <email>kris@sitepen.com</email>
            </address>
        </author>

        <author fullname="Gary Court" initials="G" surname="Court">
            <address>
                <postal>
                    <street></street>
                    <city>Calgary, AB</city>
                    <country>Canada</country>
                </postal>
                <email>gary.court@gmail.com</email>
            </address>
        </author>

        <date year="2013"/>
        <workgroup>Internet Engineering Task Force</workgroup>
        <keyword>JSON</keyword>
        <keyword>Schema</keyword>
        <keyword>validation</keyword>

        <abstract>
            <t>
                JSON Schema (application/schema+json) has several purposes, one of which is instance
                validation. The validation process may be interactive or non interactive. For
                instance, applications may use JSON Schema to build a user interface enabling
                interactive content generation in addition to user input checking, or validate data
                retrieved from various sources. This specification describes schema keywords
                dedicated to validation purposes.
            </t>
        </abstract>
    </front>

    <middle>
        <section title="Introduction">
            <t>
                JSON Schema can be used to require that a given JSON document (an instance)
                satisfies a certain number of criteria. These criteria are materialized by a set of
                keywords which are described in this specification. In addition, a set of keywords
                is defined to assist in interactive instance generation. Those are also described in
                this specification.
            </t>

            <t>
                This specification will use the terminology defined by the JSON Schema core
                specification. It is advised that readers have a copy of this specification.
            </t>

        </section>

        <section title="Conventions and Terminology">
            <t>
                <!-- The text in this section has been copied from the official boilerplate,
                and should not be modified.-->

                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 <xref target="RFC2119">RFC 2119</xref>.
            </t>

            <t>
                This specification uses the term "container instance" to refer to both array and
                object instances. It uses the term "children instances" to refer to array elements
                or object member values.
            </t>

            <t>
                This specification uses the term "property set" to refer to the set of an object's
                member names; for instance, the property set of JSON Object { "a": 1, "b": 2 } is [
                "a", "b" ].
            </t>

            <t>
                Elements in an array value are said to be unique if no two elements of this array
                are equal, as defined by the core specification.
            </t>
        </section>

        <section title="Interoperability considerations">

            <section title="Validation of string instances">

                <t>
                    It should be noted that the nul character (\x00) is valid in a JSON string. An
                    instance to validate may contain a string value with this character, regardless
                    of the ability of the underlying programming language to deal with such data.
                </t>

            </section>

            <section title="Validation of numeric instances">

                <t>
                    The JSON specification does not define any bounds to the scale or precision of
                    numeric values. JSON Schema does not define any such bounds either. This means
                    that numeric instances processed by JSON Schema can be arbitrarily large and/or
                    have an arbitrarily large decimal part, regardless of the ability of the
                    underlying programming language to deal with such data.
                </t>

            </section>

            <section title="Regular expressions">

                <t>
                    Two validation keywords, "pattern" and "patternProperties", use regular
                    expressions to express constraints. These regular expressions SHOULD
                    be valid according to the <xref target="ecma262">ECMA 262</xref> regular
                    expression dialect.
                </t>
                
                <t>
                    Furthermore, given the high disparity in regular expression constructs support,
                    schema authors SHOULD limit themselves to the following regular expression
                    tokens:

                    <list>
                        <t>individual Unicode characters, as defined by the <xref
                        target="RFC4627">JSON specification</xref>;</t>
                        <t>simple character classes ([abc]), range character classes ([a-z]);</t>
                        <t>complemented character classes ([^abc], [^a-z]);</t>
                        <t>simple quantifiers: "+" (one or more), "*" (zero or more), "?" (zero or
                        one), and their lazy versions ("+?", "*?", "??");</t>
                        <t>range quantifiers: "{x}" (exactly x occurrences), "{x,y}" (at least x, at
                        most y, occurrences), {x,} (x occurrences or more), and their lazy
                        versions;</t>
                        <t>the beginning-of-input ("^") and end-of-input ("$") anchors;</t>
                        <t>simple grouping ("(...)") and alternation ("|").</t>
                    </list>
                </t>

                <t>
                    Finally, implementations MUST NOT consider that regular expressions are
                    anchored, neither at the beginning nor at the end. This means, for instance,
                    that "es" matches "expression".
                </t>

            </section>

        </section>

        <section title="General validation considerations">

            <section title="Keywords and instance primitive types">

                <t>
                    Some validation keywords only apply to one or more primitive types. When the
                    primitive type of the instance cannot be validated by a given keyword,
                    validation for this keyword and instance SHOULD succeed.
                </t>

                <t>
                    This specification groups keywords in different sections, according to the
                    primitive type, or types, these keywords validate. Note that some keywords
                    validate all instance types.
                </t>

            </section>

            <section title="Inter-dependent keywords">

                <t>
                    In order to validate an instance, some keywords are influenced by the presence
                    (or absence) of other keywords. In this case, all these keywords will be grouped
                    in the same section.
                </t>

            </section>

            <section title="Default values for missing keywords">

                <t>
                    Some keywords, if absent, MAY be regarded by implementations as having
                    a default value. In this case, the default value will be mentioned.
                </t>

            </section>

            <section title="Validation of container instances">

                <t>
                    Keywords with the possibility to validate container instances (arrays or
                    objects) only validate the instances themselves and not their children (array
                    items or object properties). Some of these keywords do, however, contain
                    information which is necessary for calculating which schema(s) a child must be
                    valid against. The algorithms to calculate a child instance's relevant schema(s)
                    are explained in a separate section.
                </t>

                <t>
                    It should be noted that while an array element will only have to validate
                    against one schema, object member values may have to validate against more than
                    one schema.
                </t>
            </section>

        </section>

        <section title="Validation keywords sorted by instance types">

            <section title="Validation keywords for numeric instances (number and integer)">

                <section title="multipleOf">

                    <section title="Valid values">
                        <t>
                            The value of "multipleOf" MUST be a JSON number. This number MUST be
                            strictly greater than 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            A numeric instance is valid against "multipleOf" if the
                            result of the division of the instance by this keyword's value is
                            an integer.
                        </t>
                    </section>

                </section>

                <section title="maximum and exclusiveMaximum">

                    <section title="Valid values">
                        <t>
                            The value of "maximum" MUST be a JSON number. The value of
                            "exclusiveMaximum" MUST be a boolean.
                        </t>

                        <t>
                            If "exclusiveMaximum" is present, "maximum" MUST also be present.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            Successful validation depends on the presence and value of
                            "exclusiveMaximum":

                            <list>
                                <t>if "exclusiveMaximum" is not present, or has boolean value false,
                                then the instance is valid if it is lower than, or equal to, the
                                value of "maximum";</t>
                                <t>if "exclusiveMaximum" has boolean value true, the instance is
                                valid if it is strictly lower than the value of "maximum".</t>
                            </list>
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            "exclusiveMaximum", if absent, may be considered as being present with
                            boolean value false.
                        </t>
                    </section>
                </section>

                <section title="minimum and exclusiveMinimum">

                    <section title="Valid values">
                        <t>
                            The value of "minimum" MUST be a JSON number. The value of
                            "exclusiveMinimum" MUST be a boolean.
                        </t>

                        <t>
                            If "exclusiveMinimum" is present, "minimum" MUST also be present.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            Successful validation depends on the presence and value of
                            "exclusiveMinimum":

                            <list>
                                <t>if "exclusiveMinimum" is not present, or has boolean value false,
                                then the instance is valid if it is greater than, or equal to, the
                                value of "minimum";</t>
                                <t>if "exclusiveMinimum" is present and has boolean value true, the
                                instance is valid if it is strictly greater than the value of
                                "minimum".</t>
                            </list>
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            "exclusiveMinimum", if absent, may be considered as being present with
                            boolean value false.
                        </t>
                    </section>
                </section>

            </section>

            <section title="Validation keywords for strings">

                <section title="maxLength">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            A string instance is valid against this keyword if its
                            length is less than, or equal to, the value of this keyword.
                        </t>

                        <t>
                            The length of a string instance is defined as the number of its
                            characters as defined by <xref target="RFC4627">RFC 4627</xref>.
                        </t>
                    </section>

                </section>

                <section title="minLength">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            A string instance is valid against this keyword if its
                            length is greater than, or equal to, the value of this keyword.
                        </t>

                        <t>
                            The length of a string instance is defined as the number of its
                            characters as defined by <xref target="RFC4627">RFC 4627</xref>.
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            "minLength", if absent, may be considered as being present with integer
                            value 0.
                        </t>
                    </section>

                </section>

                <section title="pattern">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be a string. This string SHOULD be a
                            valid regular expression, according to the ECMA 262 regular expression
                            dialect.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            A string instance is considered valid if the regular
                            expression matches the instance successfully. Recall: regular
                            expressions are not implicitly anchored.
                        </t>

                    </section>

                </section>

            </section>

            <section title="Validation keywords for arrays">

                <section title="additionalItems and items">

                    <section title="Valid values">
                        <t>
                            The value of "additionalItems" MUST be either a boolean or an object. If
                            it is an object, this object MUST be a valid JSON Schema.
                        </t>

                        <t>
                            The value of "items" MUST be either an object or an array. If it is an
                            object, this object MUST be a valid JSON Schema. If it is an array,
                            items of this array MUST be objects, and each of these objects MUST be a
                            valid JSON Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            Successful validation of an array instance with regards to these two
                            keywords is determined as follows:

                            <list>
                                <t>if "items" is not present, or its value is an object, validation
                                of the instance always succeeds, regardless of the value of
                                "additionalItems";</t>
                                <t>if the value of "additionalItems" is boolean value true or an
                                object, validation of the instance always succeeds;</t>
                                <t>if the value of "additionalItems" is boolean value false and the
                                value of "items" is an array, the instance is valid if
                                its size is less than, or equal to, the size of "items".</t>
                            </list>
                        </t>
                    </section>

                    <section title="Example">
                        <t>
                            The following example covers the case where "additionalItems" has
                            boolean value false and "items" is an array, since this is the only
                            situation under which an instance may fail to validate successfully.
                        </t>

                        <figure>
                            <preamble>This is an example schema:</preamble>
                            <artwork>
<![CDATA[
{
    "items": [ {}, {}, {} ],
    "additionalItems": false
}
]]>
                            </artwork>
                        </figure>

                        <t>
                            With this schema, the following instances are valid:

                            <list>
                                <t>[] (an empty array),</t>
                                <t>[ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ] ],</t>
                                <t>[ 1, 2, 3 ];</t>
                            </list>
                        </t>

                        <t>
                            the following instances are invalid:

                            <list>
                                <t>[ 1, 2, 3, 4 ],</t>
                                <t>[ null, { "a": "b" }, true, 31.000002020013 ]</t>
                            </list>
                        </t>
                    </section>

                    <section title="Default values">
                        <t>
                            If either keyword is absent, it may be considered present with an empty
                            schema.
                        </t>
                    </section>
                </section>

                <section title="maxItems">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An array instance is valid against "maxItems" if its size is
                            less than, or equal to, the value of this keyword.
                        </t>
                    </section>

                </section>

                <section title="minItems">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An array instance is valid against "minItems" if its size is
                            greater than, or equal to, the value of this keyword.
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            If this keyword is not present, it may be considered present with a
                            value of 0.
                        </t>
                    </section>

                </section>

                <section title="uniqueItems">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be a boolean.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            If this keyword has boolean value false, the instance validates
                            successfully. If it has boolean value true, the instance validates
                            successfully if all of its elements are unique.
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            If not present, this keyword may be considered present with boolean
                            value false.
                        </t>
                    </section>

                </section>

            </section>

            <section title="Validation keywords for objects">

                <section title="maxProperties">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An object instance is valid against "maxProperties" if its
                            number of properties is less than, or equal to, the value of this
                            keyword.
                        </t>
                    </section>

                </section>

                <section title="minProperties">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an integer. This integer MUST be
                            greater than, or equal to, 0.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An object instance is valid against "minProperties" if its
                            number of properties is greater than, or equal to, the value of this
                            keyword.
                        </t>
                    </section>

                    <section title="Default value">
                        <t>
                            If this keyword is not present, it may be considered present with a
                            value of 0.
                        </t>
                    </section>

                </section>

                <section title="required">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an array. This array MUST have at
                            least one element. Elements of this array MUST be strings, and MUST be
                            unique.
                        </t>

                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An object instance is valid against this keyword if its
                            property set contains all elements in this keyword's array value.
                        </t>
                    </section>

                </section>

                <section title="additionalProperties, properties and patternProperties">

                    <section title="Valid values">
                        <t>
                            The value of "additionalProperties" MUST be a boolean or an object. If
                            it is an object, it MUST also be a valid JSON Schema.
                        </t>

                        <t>
                            The value of "properties" MUST be an object. Each value of this object
                            MUST be an object, and each object MUST be a valid JSON Schema.
                        </t>

                        <t>
                            The value of "patternProperties" MUST be an object. Each property name
                            of this object SHOULD be a valid regular expression, according to the
                            ECMA 262 regular expression dialect. Each property value of this object
                            MUST be an object, and each object MUST be a valid JSON Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            Successful validation of an object instance against these three keywords
                            depends on the value of "additionalProperties":

                            <list>
                                <t>if its value is boolean true or a schema, validation
                                succeeds;</t>
                                <t>if its value is boolean false, the algorithm to determine
                                validation success is described below.</t>
                            </list>
                        </t>
                    </section>

                    <section title="Default values">
                        <t>
                            If either "properties" or "patternProperties" are absent, they can be
                            considered present with an empty object as a value.
                        </t>

                        <t>
                            If "additionalProperties" is absent, it may be considered present with
                            an empty schema as a value.
                        </t>
                    </section>

                    <section title='If "additionalProperties" has boolean value false'>
                        <t>
                            In this case, validation of the instance depends on the property set of
                            "properties" and "patternProperties". In this section, the property
                            names of "patternProperties" will be called regexes for convenience.
                        </t>

                        <t>
                            The first step is to collect the following sets:

                            <list style="hanging">
                                <t hangText="s">The property set of the instance to validate.</t>
                                <t hangText="p">The property set from "properties".</t>
                                <t hangText="pp">The property set from "patternProperties".</t>
                            </list>
                        </t>

                        <t>
                            Having collected these three sets, the process is as follows:

                            <list>
                                <t>remove from "s" all elements of "p", if any;</t>
                                <t>for each regex in "pp", remove all elements of "s" which this
                                regex matches.</t>
                            </list>
                        </t>

                        <t>
                            Validation of the instance succeeds if, after these two
                            steps, set "s" is empty.
                        </t>
                    </section>

                    <section title="Example">

                        <t>
                            This schema will be used as an example:
                        </t>

                        <figure>
                            <artwork>
<![CDATA[
{
    "properties": {
        "p1": {}
    },
    "patternProperties": {
        "p": {},
        "[0-9]": {}
    },
    "additionalProperties": false
}
]]>
                            </artwork>
                        </figure>

                        <t>
                            This is the instance to validate:
                        </t>

                        <figure>
                            <artwork>
<![CDATA[
{
    "p1": true,
    "p2": null,
    "a32&o": "foobar",
    "": [],
    "fiddle": 42,
    "apple": "pie"
}
]]>
                            </artwork>
                        </figure>

                        <t>
                            The three property sets are:

                            <list style="hanging">
                                <t hangText="s">[ "p1", "p2", "a32&o", "", "fiddle", "apple"
                                ]</t>
                                <t hangText="p">[ "p1" ]</t>
                                <t hangText="pp">[ "p", "[0-9]" ]</t>
                            </list>
                        </t>

                        <t>
                            Applying the two steps of the algorithm:

                            <list>
                                <t>after the first step, "p1" is removed from "s";</t>
                                <t>after the second step, "p2" (matched by "p"), "a32&o"
                                (matched by "[0-9]") and "apple" (matched by "p") are removed from
                                "s".</t>
                            </list>
                        </t>

                        <t>
                            The set "s" still contains two elements, "" and "fiddle". Validation
                            therefore fails.
                        </t>
                    </section>

                </section>

                <section title="dependencies">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an object. Each value of this object MUST
                            be either an object or an array.
                        </t>

                        <t>
                            If the value is an object, it MUST be a valid JSON Schema. This is
                            called a schema dependency.
                        </t>

                        <t>
                            If the value is an array, it MUST have at least one element. Each
                            element MUST be a string, and elements in the array MUST be unique. This
                            is called a property dependency.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <section title="Schema dependencies">
                            <t>
                                For all (name, schema) pair of schema dependencies, if the instance
                                has a property by this name, then it must also validate successfully
                                against the schema.
                            </t>

                            <t>
                                Note that this is the instance itself which must validate
                                successfully, not the value associated with the property name.
                            </t>
                        </section>

                        <section title="Property dependencies">
                            <t>
                                For each (name, propertyset) pair of property dependencies, if the
                                instance has a property by this name, then it must also have
                                properties with the same names as propertyset.
                            </t>
                        </section>

                    </section>

                </section>

            </section>

            <section title="Validation keywords for any instance type">

                <section title="enum">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be an array. This array MUST have at
                            least one element. Elements in the array MUST be unique.
                        </t>

                        <t>
                            Elements in the array MAY be of any type, including null.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance validates successfully against this keyword if its value is
                            equal to one of the elements in this keyword's array value.
                        </t>
                    </section>

                </section>

                <section title="type">

                    <section title="Valid values">
                        <t>
                            The value of this keyword MUST be either a string or an array. If it is
                            an array, elements of the array MUST be strings and MUST be unique.
                        </t>

                        <t>
                            String values MUST be one of the seven primitive types defined by
                            the core specification.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance matches successfully if its primitive type is one of the
                            types defined by keyword. Recall: "number" includes "integer".
                        </t>
                    </section>
                </section>

                <section title="allOf">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an array. This array MUST have at least one
                            element.
                        </t>

                        <t>
                            Elements of the array MUST be objects. Each object MUST be a valid JSON
                            Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance validates successfully against this keyword if it validates
                            successfully against all schemas defined by this keyword's value.
                        </t>
                    </section>

                </section>

                <section title="anyOf">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an array. This array MUST have at least one
                            element.
                        </t>

                        <t>
                            Elements of the array MUST be objects. Each object MUST be a valid JSON
                            Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance validates successfully against this keyword if it validates
                            successfully against at least one schema defined by this keyword's value.
                        </t>
                    </section>

                </section>

                <section title="oneOf">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an array. This array MUST have at least one
                            element.
                        </t>

                        <t>
                            Elements of the array MUST be objects. Each object MUST be a valid JSON
                            Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance validates successfully against this keyword if it validates
                            successfully against exactly one schema defined by this keyword's value.
                        </t>
                    </section>

                </section>

                <section title="not">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an object. This object MUST be a valid JSON
                            Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            An instance is valid against this keyword if it fails to validate
                            successfully against the schema defined by this keyword.
                        </t>
                    </section>

                </section>

                <section title="definitions">

                    <section title="Valid values">
                        <t>
                            This keyword's value MUST be an object. Each member value of this object
                            MUST be a valid JSON Schema.
                        </t>
                    </section>

                    <section title="Conditions for successful validation">
                        <t>
                            This keyword plays no role in validation per se. Its role is to provide
                            a standardized location for schema authors to inline JSON Schemas into a
                            more general schema.
                        </t>

                        <t>
                            As an example, here is a schema describing an array of positive
                            integers, where the positive integer constraint is a subschema in
                            "definitions":

                            <figure>
                                <artwork>
<![CDATA[
{
    "type": "array",
    "items": { "$ref": "#/definitions/positiveInteger" },
    "definitions": {
        "positiveInteger": {
            "type": "integer",
            "minimum": 0,
            "exclusiveMinimum": true
        }
    }
}
]]>
                                </artwork>
                            </figure>
                        </t>
                    </section>
                </section>
            </section>

        </section>

        <section title="Metadata keywords">

            <section title='"title" and "description"'>

                <section title="Valid values">
                    <t>
                        The value of both of these keywords MUST be a string.
                    </t>
                </section>

                <section title="Purpose">
                    <t>
                        Both of these keywords can be used to decorate a user interface with
                        information about the data produced by this user interface. A title will
                        preferrably be short, whereas a description will provide explanation about
                        the purpose of the instance described by this schema.
                    </t>

                    <t>
                        Both of these keywords MAY be used in root schemas, and in any subschemas.
                    </t>
                </section>

            </section>

            <section title='"default"'>

                <section title="Valid values">
                    <t>
                        There are no restrictions placed on the value of this keyword.
                    </t>
                </section>

                <section title="Purpose">
                    <t>
                        This keyword can be used to supply a default JSON value associated with a
                        particular schema. It is RECOMMENDED that a default value be valid against
                        the associated schema.
                    </t>

                    <t>
                        This keyword MAY be used in root schemas, and in any subschemas.
                    </t>
                </section>

            </section>
        </section>

        <section title='Semantic validation with "format"'>

            <section title="Foreword">
                <t>
                    Structural validation alone may be insufficient to validate that an instance
                    meets all the requirements of an application. The "format" keyword is defined to
                    allow interoperable semantic validation for a fixed subset of values which are
                    accurately described by authoritative resources, be they RFCs or other external
                    specifications.
                </t>

                <t>
                    The value of this keyword is called a format attribute. It MUST be a string. A
                    format attribute can generally only validate a given set of instance types. If
                    the type of the instance to validate is not in this set, validation for this
                    format attribute and instance SHOULD succeed.
                </t>

            </section>

            <section title="Implementation requirements">
                <t>
                    Implementations MAY support the "format" keyword. Should they choose to do so:
                    
                    <list>
                        <t>they SHOULD implement validation for attributes defined below;</t>
                        <t>they SHOULD offer an option to disable validation for this keyword.</t>
                    </list>
                    
                </t>

                <t>
                    Implementations MAY add custom format attributes. Save for agreement between
                    parties, schema authors SHALL NOT expect a peer implementation to support this
                    keyword and/or custom format attributes.
                </t>
            </section>

            <section title="Defined attributes">

                <section title="date-time">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid date
                            representation as defined by <xref target="RFC3339">RFC 3339, section
                            5.6</xref>.
                        </t>
                    </section>
                </section>

                <section title="email">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid
                            Internet email address as defined by <xref target="RFC5322">RFC 5322,
                            section 3.4.1</xref>.
                        </t>
                    </section>
                </section>
                <section title="hostname">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid
                            representation for an Internet host name, as defined by <xref
                            target="RFC1034">RFC 1034, section 3.1</xref>.
                        </t>
                    </section>
                </section>

                <section title="ipv4">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid
                            representation of an IPv4 address according to the "dotted-quad" ABNF
                            syntax as defined in <xref target="RFC2673">RFC 2673, section
                            3.2</xref>.
                        </t>
                    </section>
                </section>

                <section title="ipv6">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid
                            representation of an IPv6 address as defined in <xref
                            target="RFC2373">RFC 2373, section 2.2</xref>.
                        </t>
                    </section>
                </section>

                <section title="uri">
                    <section title="Applicability">
                        <t>
                            This attribute applies to string instances.
                        </t>
                    </section>

                    <section title="Validation">
                        <t>
                            A string instance is valid against this attribute if it is a valid URI,
                            according to <xref target="RFC3986"/>.
                        </t>
                    </section>
                </section>

            </section>
        </section>

        <section title="Reference algorithms for calculating children schemas">

            <section title="Foreword">
                <t>
                    Calculating the schema, or schemas, a child instance must validate against is
                    influenced by the following:

                    <list>
                        <t>the container instance type;</t>
                        <t>the child instance's defining characteristic in the container
                        instance;</t>
                        <t>the value of keywords implied in the calculation.</t>
                    </list>
                </t>

                <t>
                    In addition, it is important that if one or more keyword(s) implied in the
                    calculation are not defined, they be considered present with their default
                    value, which will be recalled in this section.
                </t>
            </section>

            <section title="Array elements">

                <section title="Defining characteristic">
                    <t>
                        The defining characteristic of the child instance is its index within the
                        array. Recall: array indices start at 0.
                    </t>
                </section>

                <section title="Implied keywords and default values.">
                    <t>
                        The two implied keywords in this calculation are "items" and
                        "additionalItems".
                    </t>

                    <t>
                        If either keyword is absent, it is considered present with an empty schema as a
                        value. In addition, boolean value true for "additionalItems" is considered
                        equivalent to an empty schema.
                    </t>
                </section>

                <section title="Calculation">

                    <section title='If "items" is a schema'>
                        <t>
                            If items is a schema, then the child instance must be valid against this
                            schema, regardless of its index, and regardless of the value of
                            "additionalItems".
                        </t>
                    </section>

                    <section title='If "items" is an array'>
                        <t>
                            In this situation, the schema depends on the index:

                            <list>
                                <t>if the index is less than, or equal to, the size of "items", the
                                child instance must be valid against the corresponding schema in the
                                "items" array;</t>
                                <t>otherwise, it must be valid against the schema defined by
                                "additionalItems".</t>
                            </list>
                        </t>
                    </section>
                </section>

            </section>

            <section title="Object members">

                <section title="Defining characteristic">
                    <t>
                        The defining characteristic is the property name of the child.
                    </t>
                </section>

                <section title="Implied keywords">
                    <t>
                        The three keywords implied in this calculation are "properties",
                        "patternProperties" and "additionalProperties".
                    </t>

                    <t>
                        If "properties" or "patternProperties" are absent, they are considered
                        present with an empty object as a value.
                    </t>

                    <t>
                        If "additionalProperties" is absent, it is considered present with an empty
                        schema as a value. In addition, boolean value true is considered equivalent
                        to an empty schema.
                    </t>
                </section>

                <section title="Calculation">

                    <section title="Names used in this calculation">
                        <t>
                            The calculation below uses the following names:

                            <list style="hanging">
                                <t hangText="m">The property name of the child.</t>
                                <t hangText="p">The property set from "properties".</t>
                                <t hangText="pp">The property set from "patternProperties". Elements
                                of this set will be called regexes for convenience.</t>
                                <t hangText="s">The set of schemas for the child instance.</t>
                            </list>
                        </t>

                    </section>

                    <section title='First step: schemas in "properties"'>
                        <t>
                            If set "p" contains value "m", then the corresponding schema in
                            "properties" is added to "s".
                        </t>
                    </section>

                    <section title='Second step: schemas in "patternProperties"'>
                        <t>
                            For each regex in "pp", if it matches "m" successfully, the
                            corresponding schema in "patternProperties" is added to "s".
                        </t>
                    </section>

                    <section title='Third step: "additionalProperties"'>
                        <t>
                            The schema defined by "additionalProperties" is added to "s" if and only
                            if, at this stage, "s" is empty.
                        </t>
                    </section>
                </section>
            </section>
        </section>

        <section title="Security considerations">
            <t>
                JSON Schema validation does not have any additional security considerations than
                those defined by the JSON Schema core specification.
            </t>
        </section>

        <section title="IANA Considerations">
            <t>
                This specification does not have any influence with regards to IANA.
            </t>

        </section>
    </middle>

    <back>
        <!-- References Section -->
        <references title="Normative References">
            &RFC2119;
        </references>

        <references title="Informative References">
            &RFC1034;
            &RFC2373;
            &RFC2673;
            &RFC3339;
            &RFC3986;
            &RFC4627;
            &RFC5322;
            <reference anchor="ecma262"
            target="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf">
                <front>
                    <title>ECMA 262 specification</title>
                    <author/>
                    <date/>
                </front>
            </reference>
        </references>

        <section title="ChangeLog">
            <t>
                <list style="hanging">
                    <t hangText="draft-00">
                        <list style="symbols">
                            <t>Initial draft.</t>
                            <t>Salvaged from draft v3.</t>
                            <t>Redefine the "required" keyword.</t>
                            <t>Remove "extends", "disallow"</t>
                            <t>Add "anyOf", "allOf", "oneOf", "not", "definitions", "minProperties",
                            "maxProperties".</t>
                            <t>"dependencies" member values can no longer be single strings; at
                            least one element is required in a property dependency array.</t>
                            <t>Rename "divisibleBy" to "multipleOf".</t>
                            <t>"type" arrays can no longer have schemas; remove "any" as a possible
                            value.</t>
                            <t>Rework the "format" section; make support optional.</t>
                            <t>"format": remove attributes "phone", "style", "color"; rename
                            "ip-address" to "ipv4"; add references for all attributes.</t>
                            <t>Provide algorithms to calculate schema(s) for array/object
                            instances.</t>
                            <t>Add interoperability considerations.</t>
                        </list>
                    </t>
                </list>
            </t>
        </section>
    </back>
</rfc>

PAFTECH AB 2003-20262026-04-24 17:17:56