Skip to the content.

One-of and Any-of

Example schema to demonstrate one of and any of

$idoneof-and-anyof.yml
$schemahttp://json-schema.org/draft-07/schema#

Properties

NameType
justOneOne of:Object
Object

Example

{
    "justOne": {
        "propertyA": "With a string value"
    }
}

Example

{
    "justOne": {
        "propertyB": 123,
        "propertyC": 456
    }
}

justOne

Title Just One
Description Property that demonstrates oneOf
Required Yes
TypeOne of:Object
Object

justOne.0

Title justOne option 0 with a single property

justOne.0.propertyA

Title Property A
TypeString

justOne.1

Title justOne option 1 with two properties

justOne.1.propertyB

Title Property B
TypeInteger

justOne.1.propertyC

Title Property C
TypeInteger

Schema

{
    "$id": "oneof-and-anyof.yml",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "One-of and Any-of",
    "description": "Example schema to demonstrate one of and any of",
    "type": "object",
    "examples": [
        {
            "justOne": {
                "propertyA": "With a string value"
            }
        },
        {
            "justOne": {
                "propertyB": 123,
                "propertyC": 456
            }
        }
    ],
    "properties": {
        "justOne": {
            "title": "Just One",
            "description": "Property that demonstrates oneOf",
            "type": "object",
            "oneOf": [
                {
                    "title": "justOne option 0 with a single property",
                    "properties": {
                        "propertyA": {
                            "type": "string",
                            "title": "Property A"
                        }
                    },
                    "required": [
                        "propertyA"
                    ]
                },
                {
                    "title": "justOne option 1 with two properties",
                    "properties": {
                        "propertyB": {
                            "type": "integer",
                            "title": "Property B"
                        },
                        "propertyC": {
                            "type": "integer",
                            "title": "Property C"
                        }
                    },
                    "required": [
                        "propertyB",
                        "propertyC"
                    ]
                }
            ],
            "isRequired": true
        }
    },
    "additionalProperties": false,
    "required": [
        "justOne"
    ]
}