spiffytech
spiffytech

Reputation: 6642

Dynamic list of valid values in JSON Schema

Given the following JSON, how can I use JSON Schema to validate that each string in nodes[].targets matches the name of a listed node?

{
    "nodes": [
        {"name": "app_server"},
        {"name": "web_server1"}
        {"name": "web_server2"}
        {
            "name": "load_balancer",
            "targets": ["web_server1", "web_server2"]
        }
    ]
}

Upvotes: 2

Views: 541

Answers (1)

esp
esp

Reputation: 7717

JSON schema does not support such validation criteria.

You either need to define custom keywords if the validator supports them (e.g. in Ajv) or validate outside of schema.

Disclaimer: I have created Ajv.

Upvotes: 2

Related Questions