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

_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

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?