Vinay Prajapati
Vinay Prajapati

Reputation: 7504

json schema usage of definitions keyword

Can anyone please help me with usage of definitions in json schema. I had gone through their website and didn't get much information.

Any helps would be worth.

Upvotes: 1

Views: 2996

Answers (1)

Tim
Tim

Reputation: 43314

the definitions keyword is a standardized placeholder in which you can define inline subschemas to be used in a schema.

In other words, the definitions keyword defines subschemas that you can refer to elsewhere in the schema. Perhaps this is an easier example:

"properties": {
    "cars": {
        "type": "object",
        "oneOf": [
            { "$ref": "#/definitions/ford" },
            { "$ref": "#/definitions/bmw" },
            { "$ref": "#/definitions/audi" }
        ]
    }
},
"definitions": {
    "ford": {
        "origin": "USA"
     },
    "bmw": {
        "origin": "Germany"
    },
    "audi": {
        "origin": "Germany"
    }
}

Under definitions you define subschemas, for example for ford that you can refer to elsewhere with "$ref": "#definitions/ford".

Upvotes: 3

Related Questions