I would like to create a JSON schema that defines two entities: region
and country
.
The JSON schema for country
is as follows:
{
"$id":"https://example.com/arrays.schema.json",
"$schema":"http://json-schema.org/draft-07/schema#",
"description":"A list of countries",
"type":"array",
"items":{
"type":"object",
"required":[
"code",
"name"
],
"properties":{
"code":{
"type":"string",
"maxLength": 2,
"minLength": 2
},
"name":{
"type":"string",
}
}
}
}
This allows me to define countries in a file, lets call it countries.json
:
[
{ "code": "GB", "name": "United Kingdom"},
{ "code": "US", "name": "United States of America"}
]
I would now like to define a schema for region
. Here is an example file that I would consider valid:
[
{ "name": "Europe", "countries": [ "GB" ] },
{ "name": "North America", "countries": [ "US" ] }
]
The countries
attribute needs to be validated against the contents of countries.json
. How can this be achieved? I do not want to use the enum
type and repeat the list of countries in the region
schema