get json query result
Name | Description | Type | Modifier |
---|---|---|---|
json | JSON target document that the query runs against. | String | None |
jsonpath | JSONPath query string | String | None |
variable | (Optional) Variable to receive the returned query result. | String | None |
Given the following JSON document:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
To insert the entire JSON document's content above into the json argument, for example, use JSON Editor Online to remove all white spaces. The returned JSON document resembles the following.
{"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"Herman Melville","title":"Moby Dick","isbn":"0-553-21311-3","price":8.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}}}
json jsonpath variable
get json query result {"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99},{"category":"fiction","author":"Herman Melville","title":"Moby Dick","isbn":"0-553-21311-3","price":8.99},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],"bicycle":{"color":"red","price":19.95}}} store.book[0].category >>category
- JSONPath of REST Assured, a Java framework for simplifying testing of REST based services and currently employed in TestArchitect, uses Groovy GPath expressions. A tutorial on GPath is beyond the scope of this help system. For more information on GPath, you can refer to this site.
To insert an entire JSON document’s content into the json argument, all whitespaces must be removed manually to avoid automation failure.
Tip:You can use various tools to compact JSON data to remove all whitepsaces. For example: JSON Editor Online.- If the variable in argument variable has not been declared, the action creates it as a global.
- This action supports the <ignore> modifier. If the string
<ignore>
is present as the value of any of the arguments, or any argument contains an expression that evaluates to<ignore>
, the action is skipped during execution.