Liquid Studio 2021
JSON Schema Editor / Graphical Notation Overview / Array Item Container
In This Topic
    Array Item Container
    In This Topic
    Draft 04 Draft 06 Draft 07 Draft 2019-09

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

    The visual representation shows the schema that will be applied to the items at a given index in the instance array.

    Array Items

    An 'Array Item' node shows the index it applies too in the instance array.

    Additional Array Items

    An 'Additional Items' node is one which covers a range of indexes i.e. [0-n], in this case the schema is used to validate items in the instance array with corresponding indexes.

    Example 1

    Array Items 'List' Validation
    Copy Code
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",    "additionalProperties": false,
        "properties": {
            "Users": {
                "additionalItems": false,
                "items": {
                    "type": "string"
                },
                "type": "array"
            }
        }
    }
    

    So the following is valid

    Valid JSON Instance Document
    Copy Code
    { "Users": [ "Alice", "Bob", "Eve" ] }
    
    Invalid JSON Instance Document (as 5 is not a string)
    Copy Code
    { "Users": [ "Alice", 5, "Eve" ] }
    

     

    Example 2

    Array Items 'List' Validation
    Copy Code
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",    "additionalProperties": false,
        "properties": {
            "Values": {
                "additionalItems": false,
                "items": [
                    { "type": "integer" },
                    { "type": "string"  },
                    { "type": "boolean" }
                ],
                "type": "array"
            }
        }
    }
    

     The array item shows the index items it applies too in the instance value;

    The value at index 0 must be an integer.

    The value at index 1 must be a string.

    The value at index 2 must be a boolean.

    So the following are valid

    Valid JSON Instance Document
    Copy Code
    { "Values": [ 5, "Bob", true ] }
    
    { "Values": [ 5, "Bob" ] }
    
    { "Values": [ ] }
    
    Invalid JSON Instance Document
    Copy Code
    { "Users": [ "5", "Bob", true ] } // Note "5" is not an integer it's a string
    
    { "Users": [ 5, "Bob", true, "Extra Value" ] } 
    

     

    Example 3

    Array Items 'List' Validation
    Copy Code
    {    "$schema": "http://json-schema.org/draft-04/schema#",    "type": "object",    "additionalProperties": false,    "properties": {        "Values": {            "type": "array",            "additionalItems": {                "type": "string"            },            "items": [
                    { "type": "integer" },
                    { "type": "string"  },
                    { "type": "boolean" }
                ]        }    }}
    

     The array item shows the index items it applies too in the instance value;

    The value at index 0 must be an integer.

    The value at index 1 must be a string.

    The value at index 2 must be a boolean.

    The value at index 3 or above must be a string.

    So the following are valid

    Valid JSON Instance Document
    Copy Code
    { "Values": [ ] }
    
    { "Values": [ 5, "Bob" ] }
    
    { "Values": [ 5, "Bob", true ] }
    
    { "Values": [ 5, "Bob", true, "another string", "and another" ] }
    
    Invalid JSON Instance Document
    Copy Code
    { "Users": [ "5", "Bob", true ] } // Note "5" is not an integer it's a string
    
    { "Users": [ 5, "Bob, "another string" ] } // Note item at index 2 must be a boolean ("another string" is a string).
    

     Contains (from Draft 6)

    The contains property was introduced in Draft 6, the property describes a schema and specifies that the array in the JSON instance document must contain at least one item which validates against the Contains schema.

    JSON Schema
    Copy Code
    "AnArrayOfStrings": {
        "type": "array",
        "items": {
            "type": "string"
        },
        "contains": {
            "type": "string",
            "const": "My Required Value"
        }
    },
    

     The schema above specifies a property 'AnArrayOfStrings', and at least one item in the array must be a string "My Required Value".

    Valid JSON  instance Document
    Copy Code
    "AnArrayOfStrings" : [ "a", "b", "My Required Value", "x" ]
    

     

    See Also