Each failing assert or report is one validation error. Its text is the item's message, after a prefix made of its labels.
An item without message reports the text of its test, as written: it is not evaluated, so quotes and \(...) in it stay as they are.
{ "assert": ".total >= 0" }
.total >= 0
A message that does not start with " is plain text. Jsontron turns it into a jq string, so it can hold \(...) interpolations, evaluated with . set to the context node and every let binding in scope:
{
"rules": [
{
"context": ".lineItems[]",
"asserts": [ { "test": ".qty <= 10", "message": "line \\(.sku): quantity \\(.qty) is over 10" } ]
}
]
}
line tea: quantity 12 is over 10
In JSON, the backslash of \( is written \\(. Inside an interpolation the text is jq, with jq's own quotes: "order \\(.id // \"?\") is late" in JSON is the message order \(.id // "?") is late. Outside the interpolations, a quote is just a character of the text.
A message that starts with " (after any leading whitespace) is a jq expression, used as it is. It can then go on after the string:
{ "assert": { "test": ".items | length > 0", "message": "\"empty order \" + (.id | tostring)" } }
The first value the message produces is the text: a string as it is, null as the empty string, any other value as its JSON text. A message that produces no value, or raises an error, gives the empty string: a message never hides a failure.
Rules and items can carry labels that make a failure easier to sort out. They do not change whether a test passes.
| Label | On | Meaning |
|---|---|---|
id |
rules, items | a name for the rule or the item |
flag |
items | a severity or category, such as error, warning or info (any non-blank string) |
role |
items | Schematron's name for flag; an item cannot have both |
Labels are trimmed of surrounding spaces, and must not be blank. The ones that are set make the prefix of the failure text, in this order, followed by a space: [<rule id>], [<item id>], [flag=<flag or role>].
{
"rules": [
{
"id": "orders",
"context": ".orders[]",
"asserts": [
{
"id": "high-value-discount",
"flag": "warning",
"test": ".total <= 1000 or .discount >= 0.1",
"message": "order \\(.id) discount is below policy"
}
]
}
],
"report": { "id": "locked", "role": "error", "test": ".locked == true", "message": "the document is locked" }
}
[orders][high-value-discount][flag=warning] order O-1 discount is below policy
[locked][flag=error] the document is locked
The second failure comes from the report sugar, merged into a rule without an id, so its prefix starts with the item's own id.