The Jsontron keywords are assertion keywords of JsonSchema.Net: a failing rule set makes its schema object invalid, and its failures come back in the EvaluationResults of JsonSchema.Evaluate with the errors of the standard keywords.
Each failing assert or report is its own result, a child of the schema object's result:
| Property | Value |
|---|---|
Errors |
one entry: the keyword that evaluates the rule set, and the failure text |
InstanceLocation |
the location of the instance the schema object applies to (not of the context node) |
EvaluationPath |
the schema object's path followed by the keyword, such as /properties/order/rules |
IsValid |
false |
The keyword is rules when the schema object has rules, else assert, else report: the merged rule set is evaluated once, by that keyword.
var schema = JsonSchema.FromText(
"""
{
"properties": {
"order": {
"rules": [
{
"context": ".lines[]",
"asserts": [ { "test": ". > 0", "message": "line \\(.) must be positive" } ]
}
]
}
}
}
""");
var result = schema.Evaluate(
JsonDocument.Parse("""{ "order": { "lines": [ -1, 2, -3 ] } }""").RootElement,
new EvaluationOptions { OutputFormat = OutputFormat.List });
foreach (var detail in result.Details ?? [])
if (detail.Errors?.TryGetValue("rules", out var message) == true)
Console.WriteLine($"{detail.InstanceLocation} {detail.EvaluationPath}: {message}");
/order /properties/order/rules: line -1 must be positive
/order /properties/order/rules: line -3 must be positive
OutputFormat.List gives every result as a flat list in Details, as above. It is the simplest to read failures from.OutputFormat.Hierarchical nests the failures under the result of their schema object.OutputFormat.Flag only tells whether the document is valid: Jsontron stops at the first failing rule set and builds no messages.When a let, a context or a test raises a jq error, the rule set stops and reports one result, under the same keyword, whose error is jq's error text. That text is not part of the specification, and may change between versions of JQLite.
var schema = JsonSchema.FromText("""{ "assert": ".total > 0" }""");
var result = schema.Evaluate(JsonDocument.Parse("[1, 2]").RootElement,
new EvaluationOptions { OutputFormat = OutputFormat.List });
// one result: assert: 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.