Liquid Studio Documentation
JSON Schema Editor / Graphical Notation Overview / Array Item Container / Additional Items
In This Topic
    Additional Items
    In This Topic
    Draft 04 Draft 06 Draft 07 Draft 2019-09 Draft 2020-12

    The Array Item Container determines the validation rules applied to an array of values in the JSON instance document.

    The index values on the 'Array Item' nodes (shown in square brackets []) indicate the index in the instance array that the schema apply's to.

    If the index value covers a range (e.g. [3-n]) then this schema will be used to validate all array items in the instance array from index 3 and above, and is referred to as the 'Additional Items' node.

    To add a schema to validate the additional array items, use the context menu 'Add Array Items -> Additional Items' from the Parent Schema or the Array Item Container.

    The 'Array Item Container' is a representation of the 'items' and 'additionalItems' keyword, the rules surrounding this are complex, and for more information see the documentation for 'additionalItems'.

    A schema can be represented in a number of different ways

    As an object

    If the schema is described an object then its properties are considered when applying the validation rules, if the object is empty then the schema is considered to match all data values and types.

    As a Boolean

    From Draft 6 and onwards anywhere a schema can appear the values true and false can be used (in Draft 4 and below this was limited to the properties  Additional Items and Additional Properties).

    When 'additionalItems' is missing

    When the 'additionalItems' property is omitted, it is implicitly read as an empty schema (i.e. one that allows anything), so by not specifying it the schema will allow any number of additional values to be appended to the array.

    When the additionalItems property is implicitly added it is shown with a * i.e. Any*

    The properties associated with an implicit additionalItems node allow it to be explicitly created using either the true or false values or declared as an empty schema.

     

     

    Array Item Validation.

    The items and additionalItems keywords control what kind of objects can appear in an instance array. They are closely interrelated and subtlety effect the validation applied. Broadly speaking there are 2 types of validation we will call them List and Tuple validation.

    Json Schema validators make assumptions about the values of the items and additionalItems keywords

    • If the items keyword is not present it is considered to contain an empty schema (which validates against everything).
    • If the additionalItems keyword is not present or true then it is considered to contain an empty schema (which validates against everything).

    List Validation

    When List validation is used, a schema is defined and all the objects in the array must validate against this schema. This is the simplest and mostly widely used form of array validation.

    List validation is used when the items keyword contains a single schema object.

    When this is the case the property additionalItems is ignored.

    Json Schema Source
    Copy Code
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "additionalItems": false,
        "additionalProperties": false,
        "properties": {
            "Users": {
                "additionalItems": false,
                "items": {
                    "type": "string"
                },
                "type": "array"
            }
        }
    }
    
    Valid Instance Json Document
    Copy Code
    {
        "Users": ["Alice","Bob", "Eve"]
    }
    

     

    Tuple Validation

    Tuple validation allows you to provide a schema to validate each item in the instance array.

    Tuple validation is used when the items property contains an array of schema objects.

    Each item in the items array validates an object in the instance array at the corresponding index.

     

    Tuple Example 1

    In this example the schema specifies the schemas for first 3 items in the array, if more than 3 items appear in the instance array then it is an error, however it is acceptable for the array to contain less than 3 items as long as the ones that are present validate against the appropriate schema.

    Json Schema Source
    Copy Code
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "additionalItems": false,
        "additionalProperties": false,
        "properties": {
            "Values": {
                "additionalItems": false,
                "items": [
                    { "type": "integer" },
                    { "type": "string"  },
                    { "type": "boolean" }
                ],
                "type": "array"
            }
        }
    }
    
    Valid Instance Json Document
    Copy Code
    {
        "Users": [34, "Bob", true]
    }
    
    Valid Instance Json Document (note: it is allowable to miss values off of the end)
    Copy Code
    {
        "Users": [34, "Bob"]
    }
    

     

    Tuple Example 2

    In this example the schema is specified for the first 3 items in the array, additionally a schema is provided for any additional array items (note the [3-n] indicator).

    The first 3 objects in the instance array must validate against the corresponding schema, but any additional items must validate against the [3-n] schema.

     

     

    Json Schema Source
    Copy Code
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "additionalItems": false,
        "additionalProperties": false,
        "properties": {
            "Values": {
                "type": "array",
                "additionalItems": {
                    "type": "string"
                },
                "items": [
                    { "type": "integer" },
                    { "type": "string"  },
                    { "type": "boolean" }
                ]
            }
        }
    }
    
    Valid Instance Json Document
    Copy Code
    {
        "Users": [34, "Bob", true]
    }
    
    Valid Instance Json Document (note: it is allowable to miss values off of the end)
    Copy Code
    {
        "Users": [34, "Bob"]
    }
    
    Valid Instance Json Document
    Copy Code
    {
        "Users": [34, "Bob", true, "Other1", "Other2"]
    }
    

     

     

    See Also