Validation By Json Path
Jason Path Verification
Verification are separated by ";"
Format
JsonPath:Position:command(value)
Position is optional
_VERIFY.JSON.PART_ store..category:1:equalTo(reference); store..category:1:equalTo(<@categoryVariable>); store..category:equalTo(reference,fiction,fiction,fiction); jsonPath: store..category Position: 1 equalTo: command value: reference
Position is optional
With position: Select json path value based on occurrence
Without position: Compare against all occurrences of json path
We can use variables for values with <@variable> syntax
Json Path 'hasItems'
Has items does partial string match if position is specified
Does Array contains match if position is not provided
_VERIFY.JSON.PART_
store..category:1:hasItems(refer);
store..category:hasItems(reference,fiction);
Json Path notHaveItems
not have items will do a 'not contains' validation on json response path
In the example case, store..category:1 will not have action.
In second example, action and adventure are not part of the store..category responses
_VERIFY.JSON.PART_
store..category:1:notHaveItems(action);
store..category:notHaveItems(action,adventure);
Json Path EqualTo
_VERIFY.JSON.PART_
store..category:1:equalTo(reference);
store..category:equalTo(reference,fiction,fiction,fiction);
Json Path notEqualTo
Will return true on store..category:1, as first response item is 'reference'
Second example is true, cause action is not part of the response
_VERIFY.JSON.PART_
store..category:1:notEqualTo(fiction);
store..category:notEqualTo(action);
Jason Path Contains
Does partial string match if position is specified
Does Array contains match if position is not provided
_VERIFY.JSON.PART_
store..category:1:contains(refer);
store..category:contains(reference,fiction);
Json Path notContains
Will do a 'not contains' validation on json response path
In the example case, store..category:1 will not have action.
In second example, action and adventure are not part of the store..category responses
_VERIFY.JSON.PART_
store..category:1:notContains(action);
store..category:notContains(action,adventure);
Json Path containsInAnyOrder
In the json response, we are verifying regardless of order
_VERIFY.JSON.PART_
store..category:containsInAnyOrder(reference,fiction);
store..category:containsInAnyOrder(fiction,reference);
Json Path integerGreaterThan
In this example, json path returns the value: 8.95, which is greater than 8
_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerGreaterThan(8);
Json Path integerLessThan
In this example, json path returns the value: 8.95, which is less than 9
_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerLessThan(9);
Json Path integerEqual
In this example, json path returns the value: 8.95, which is equal to 8.95
_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerEqual(8.95);
Json Path integerNotEqual
In this example, json path returns the value: 8.95, which is not equal to 8.96
_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerNotEqual(8.96);
Json Path nodeSizeGreaterThan
In the json response, we are verifying the number of returned categories, which is 4
_VERIFY.JSON.PART_
store..category:nodeSizeGreaterThan(3);
Json Path nodeSizeLessThan
In the json response, we are verifying the number of returned categories, which is 4
_VERIFY.JSON.PART_
store..category:nodeSizeLessThan(5);
Json Path nodeSizeExact
In the json response, we are verifying the number of returned categories, which is 4
_VERIFY.JSON.PART_
store..category:nodeSizeExact(5);
Json Path Not Empty
Verify if json path value is not empty
.book[2].category:isNotEmpty;
Json Path Empty
Verify if json path value is not empty
.book[2].category2:Empty;
Json Path Examples
JsonPath (click link to try)
Result
The authors of all books
All authors
All things, both books and bicycles
The price of everything
The third book
The second to last book
The first two books
All books from index 0 (inclusive) until index 2 (exclusive)
All books from index 1 (inclusive) until index 2 (exclusive)
Last two books
Book number two from tail
All books with an ISBN number
All books in store cheaper than 10
All books in store that are not "expensive"
All books matching regex (ignore case)
Give me every thing
The number of books
Last updated
Was this helpful?