Validation By Json Path

Jason Path Verification

  • Verification are separated by ";"

  • Format

  • 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'

_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

_VERIFY.JSON.PART_
store..category:1:notEqualTo(fiction);
store..category:notEqualTo(action);

Jason Path Contains

_VERIFY.JSON.PART_
store..category:1:contains(refer);
store..category:contains(reference,fiction);

Json Path notContains

_VERIFY.JSON.PART_
store..category:1:notContains(action);
store..category:notContains(action,adventure);

Json Path containsInAnyOrder

_VERIFY.JSON.PART_
store..category:containsInAnyOrder(reference,fiction);
store..category:containsInAnyOrder(fiction,reference);

Json Path integerGreaterThan

_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerGreaterThan(8);

Json Path integerLessThan

_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerLessThan(9);

Json Path integerEqual

_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerEqual(8.95);

Json Path integerNotEqual

_VERIFY.JSON.PART_
.book[?(@.author =~ /.*REES/i)].price:integerNotEqual(8.96);

Json Path nodeSizeGreaterThan

_VERIFY.JSON.PART_
store..category:nodeSizeGreaterThan(3);

Json Path nodeSizeLessThan

_VERIFY.JSON.PART_
store..category:nodeSizeLessThan(5);

Json Path nodeSizeExact

_VERIFY.JSON.PART_
store..category:nodeSizeExact(5);

Json Path Not Empty

.book[2].category:isNotEmpty;

Json Path Empty

.book[2].category2:Empty;

Json Path Examples

JsonPath (click link to try)

Result

$.store.book[*].author

The authors of all books

$..author

All authors

$.store.*

All things, both books and bicycles

$.store..price

The price of everything

$..book[2]

The third book

$..book[-2]

The second to last book

$..book[0,1]

The first two books

$..book[:2]

All books from index 0 (inclusive) until index 2 (exclusive)

$..book[1:2]

All books from index 1 (inclusive) until index 2 (exclusive)

$..book[-2:]

Last two books

$..book[2:]

Book number two from tail

$..book[?(@.isbn)]

All books with an ISBN number

$.store.book[?(@.price < 10)]

All books in store cheaper than 10

$..book[?(@.price <= $['expensive'])]

All books in store that are not "expensive"

$..book[?(@.author =~ /.*REES/i)]

All books matching regex (ignore case)

$..*

Give me every thing

$..book.length()

The number of books