Skip to content

Instantly share code, notes, and snippets.

@smithbr
Created February 15, 2018 01:23
Show Gist options
  • Save smithbr/2c388ab1b9d799c9fc54fe2347ff25d7 to your computer and use it in GitHub Desktop.
Save smithbr/2c388ab1b9d799c9fc54fe2347ff25d7 to your computer and use it in GitHub Desktop.
# via https://jmetervn.com/2016/09/17/json-path-postprocessor-in-jmeter/
# Extract Single Value
JSON Path expressions: $.store.book[0].author
# Output
FIRST_AUTHOR=Nigel Rees
FIRST_AUTHOR_matchNr=1
---
# Handle Multi-Match Number
JSON Path expressions: $.store.book[*].author
Match Numbers: -1
Where [*] mean all the value in book array
or
JSON Path expressions: $..author
Match Numbers: -1
# Output
AUTHOR_1=Nigel Rees
AUTHOR_2=Evelyn Waugh
AUTHOR_3=Herman Melville
AUTHOR_4=J. R. R. Tolkien
AUTHOR_matchNr=4
---
# Extract with a Condition
JSON Path expressions: $..[?(@.title == ‘The Lord of the Rings’)].price
Or
$..[?(@.title == ‘${TITLE}‘)].price
Where
[ ] – an array.
?( ) – applies a filter (script) expression.
@.title == ‘The Lord of the Rings’ – the current object which has title as child with value ‘The Lord of the Rings’
# Output
PRICE=22.99
PRICE_matchNr=1
---
# Extract Multiple values with one PostProcessor
JSON Path expressions: $..bicycle.color;$..bicycle.price
Match Numbers: 1;1
Default Values: NOT_FOUND;NOT_FOUND
# Output
BIKE_COLOR=red
BIKE_COLOR_matchNr=1
BIKE_PRICE=19.95
BIKE_PRICE_matchNr=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment