tdegrunt / jsonschema

JSON Schema validation
Other
1.83k stars 263 forks source link

JSON Schema for a list of objects that must contain one of three default props #358

Closed Roni-Ravin closed 2 years ago

Roni-Ravin commented 2 years ago

Hello, I need help... How can I prepare JSON Schema for a list of objects that must contain one of three default props (1,77,90), e.g:

VALID: [ {"provider_metadata_id": 1}, {"provider_metadata_id": 77}, {"provider_metadata_id": 90} ] VALID: [ {"provider_metadata_id": 77}, {"provider_metadata_id": 44} ] VALID: [ {"provider_metadata_id": 7884}, {"provider_metadata_id": 4564}, {"provider_metadata_id": 1} ] INVALID [ {"provider_metadata_id": 7884}, {"provider_metadata_id": 4564}, {"provider_metadata_id": 60} ] Can someone help me, please?

awwright commented 2 years ago

@Roni-Ravin This is for development of this particular library, for help writing schemas, check out the support resources at https://json-schema.org/

That said, you're probably looking for the "anyOf" keyword, something like


{ "anyOf": [
   { "properties": { "provider_metadata_id": { "const": 1 } } },
// etc
] }