Checking single properties#
Given the sample data set below, we want to check if the price of the book with the title The Lord of the Rings is greater than 10.
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95,
"tags": ["book", "Rees", "reference", "Sayings"]
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99,
"tags": ["book", "Waugh", "fiction", "Sword"]
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99,
"tags": ["book", "Melville", "fiction", "Moby"]
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99,
"tags": []
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
Steps:
Define a
refthat returns the object you are interested in. In this case we want to check thepriceof the book with the titleThe Lord of the Rings, so we can use$.store.book[?(@.title == 'The Lord of the Rings')]asref.Note
You can use the jsonPath online evaluator to check your jsonPath syntax.
Define a
conditionthat checks thepriceof the book. In this case we can use$.price > 10ascondition.Note
Of course you can also use other operators like
===,!==,<,<=or>=.
Your config file then looks like this:
checks:
- name: lotr_price_greater_than_10
ref: $.store.book[?(@.title == 'The Lord of the Rings')]
condition: $.price > 10
For the example data set above, the result of this check would be: GREEN.