I have two properties in a schema which are both arrays. I would like to compare that they're equal length.
For example:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"thing": {
"type": "object",
"properties": {
"fields": {
"type": "array",
"items": {}
},
"values": {
"type": "array",
"items": {}
}
},
"required": ["fields", "values"]
}
}
}
{
"thing": {
"fields:": ["age", "sex", "location"],
"values:": [25, "Male", "Cape Town"]
}
}
What I would like is to compare that fields and values are the same length in the schema. How would I do that?
In JSON Schema, all validation keywords are scoped to the value that it applies to. In other words, you can't validate one value in terms of another.
If you refactor this structure in almost any other way, you shouldn't have any problems.
For example, you could define a list of pairs using the array form of the items
keyword.
{
"thing": [
["age", 15],
["sex", "Male"],
["location", "Capetown"]
]
}
Or, you could use the additionalProperties
keyword and use an object to show key/value pairs in a more natural way.
{
"thing": {
"age": 15,
"sex": "Male",
"location": "Capetown"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With