You have defined your schema correctly, except that it doesn't match the data you say you are validating. If you change the property names to match the schema, you still have one issue. If you want to allow "toll" and "message" to be null, you can do the following.
{
"type": "array",
"items": {
"type": "object",
"properties": {
"loc": {
"type": "string"
},
"toll": {
"type": ["string", "null"]
},
"message": {
"type": ["string", "null"]
}
},
"required": [
"loc"
]
}
}
However, that isn't related to the error message you are getting. That message means that data you are validating is not an array. The example data you posted should not result in this error. Are you running the validator on some data other than what is posted in the question?
Answer from Jason Desrosiers on Stack OverflowYou're using the wrong variation of the items keyword. There is one form that takes a schema and another variation that takes an array of schemas.
The schema variation means all elements must match the schema. The following schema defines an array where all values are strings.
{
"items": { "type": "string" }
}
The array of schemas variation describes a tuple. The first schema validates the first item, the second schema validates the second item, and so on. The following schema validates an array where the first item is an integer, the second is string, and the third is a boolean.
{
"items": [
{ "type": "integer" },
{ "type": "string" },
{ "type": "boolean" }
]
}
It's very rare to need the tuple variation of items. You almost always want the the other one.
Your schema appears in order. I'm inclined to think this would be a bug in the implementation you're using it to validate the [1, "a"] variant. Have you tested this with different implementations or considered filing a bug with the implementation you did try here?
