Skip to the content.

Draft 2019-09 - Array Example

A schema describing fruits and vegetables

$idhttps://example.com/arrays.schema.json
$schemahttps://json-schema.org/draft/2019-09/schema

Properties

NameType
fruitsArray
vegetablesArray

Example

{
    "fruits": [
        "Apple"
    ],
    "vegetables": [
        {
            "name": "Tomato",
            "hasARoundShape": true
        },
        {
            "name": "Carrot",
            "hasARoundShape": false
        }
    ]
}

fruits

Title Fruits
Description An array of fruit names
TypeArray
Required No
Contains Type: string

vegetables

Title Vegetables
Description An array vegetable objects
TypeArray
Required No

vegetables.name

Title Name
Description The name of the vegetable.
TypeString

vegetables.hasARoundShape

Title Is round
Description Does this vegetable have a round shape?
TypeBoolean

Schema

{
    "$id": "https://example.com/arrays.schema.json",
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "title": "Draft 2019-09 - Array Example",
    "description": "A schema describing fruits and vegetables",
    "examples": [
        {
            "fruits": [
                "Apple"
            ],
            "vegetables": [
                {
                    "name": "Tomato",
                    "hasARoundShape": true
                },
                {
                    "name": "Carrot",
                    "hasARoundShape": false
                }
            ]
        }
    ],
    "type": "object",
    "properties": {
        "fruits": {
            "title": "Fruits",
            "description": "An array of fruit names",
            "type": "array",
            "contains": {
                "type": "string"
            }
        },
        "vegetables": {
            "title": "Vegetables",
            "description": "An array vegetable objects",
            "type": "array",
            "items": {
                "$ref": "#/$defs/vegetable"
            }
        }
    },
    "$defs": {
        "vegetable": {
            "type": "object",
            "required": [
                "name",
                "hasARoundShape"
            ],
            "properties": {
                "name": {
                    "type": "string",
                    "title": "Name",
                    "description": "The name of the vegetable."
                },
                "hasARoundShape": {
                    "type": "boolean",
                    "title": "Is round",
                    "description": "Does this vegetable have a round shape?"
                }
            }
        }
    }
}