Hammerite
Hammerite

Reputation: 22340

Is "description" a valid "property" for an object in a JSON schema?

Suppose I am writing a JSON schema. The "type" is "object". Is it legal to include among the "properties" for the object a property named "description"? I ask because "description" is a keyword in JSON schema.

Example: In this example I present a simple schema for JSON objects representing wine vintages. I specify four properties: three required properties (house, year, and varieties of grape) and one optional one, named "description".

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Wine vintage",
    "description": "JSON schema for wine vintages",
    "type": "object",
    "properties": {
        "house": {
            "description": "The name of the house that made the wine",
            "type": "string"
        },
        "year": {
            "description": "The year in which the wine was made",
            "type": "integer"
        },
        "varieties": {
            "description": "The grape varieties used to make the wine",
            "type": "array",
            "items": {
                "type": "string",
                "minItems": 1,
                "uniqueItems": true
            }
        }
        "description": {
            "description": "A description of the wine's taste and character; a tasting note",
            "type": "string"
        }
    },
    "required": ["house", "year", "varieties"]
}

Upvotes: 2

Views: 1369

Answers (2)

cloudfeet
cloudfeet

Reputation: 12873

The keys in "properties" never have any special meaning. You can use anything in there: "id", "description", even "$ref".

Schema keywords only have special meaning when they are directly inside a schema object.

Upvotes: 2

Brian Rogers
Brian Rogers

Reputation: 129747

I think this would be legal. I don't see anything in the spec that would specifically prohibit defining an object property name that is the same as a schema keyword. (Besides, if it did, useful and common words like "id", "type" and "items" would also be off limits as property names.)

Upvotes: 5

Related Questions