user972014
user972014

Reputation: 3856

jsonschema control property content regardless of property name

I want to write a json-schema for the following json:

{
    "peopleByID": {
        "5534": {
            "name": "Bob",
            "weight": 82
        },
        "8423": {
            "name": "Donna",
            "weight": 73
        },
        ...
    }
}

The point is that I want to control the content of each property (required to contain name and weight), while not knowing in advance the property name (the person id). I couldn't find any solution for that.

Upvotes: 0

Views: 274

Answers (1)

Ether
Ether

Reputation: 53996

additionalProperties lets you set a schema that all properties (that weren't already covered by a properties or patternProperties keyword) must conform to:

"additionalProperties": {
  "type": "object",
  "required": ["name", "weight"]
}

This is documented here.

Upvotes: 2

Related Questions