The Jsontron keywords are jsonschema keywords: a failing rule set makes the document invalid, and its failures are ValidationErrors, from iter_errors and validate like those of the standard keywords.
Each failing assert or report is one ValidationError:
| Attribute | Value |
|---|---|
message |
the failure text, with its labels |
validator |
the keyword that evaluates the rule set: rules when the schema object has it, else assert, else report |
path, json_path |
the location of the instance the schema object applies to (not of the context node) |
schema_path |
the path of the schema object followed by the keyword |
validator = JsontronValidator({
"properties": {
"order": {
"rules": [
{
"id": "lines",
"context": ".lines[]",
"asserts": [{"flag": "warning", "test": ". > 0", "message": "line \\(.) must be positive"}],
}
]
}
}
})
for error in validator.iter_errors({"order": {"lines": [-1, 2, -3]}}):
print(error.json_path, list(error.schema_path), error.message)
$.order ['properties', 'order', 'rules'] [lines][flag=warning] line -1 must be positive
$.order ['properties', 'order', 'rules'] [lines][flag=warning] line -3 must be positive
When a let, a context or a test raises a jq error, the rule set stops and gives one ValidationError, under the same keyword, whose message is Jsontron evaluation error: followed by jq's error text. That text is not part of the specification, and may change between versions of jqlite.
for error in JsontronValidator({"assert": ".total > 0"}).iter_errors([1, 2]):
print(error.message) # Jsontron evaluation error: Cannot index array with string ("total")
To keep a test from failing that way on data of an unexpected type, use ?, // or try in the expression: see jq in Jsontron.