Reputation: 1021
I'm trying to learn json jpath query. I have successfully been able to return data based on exact searches.
For example at the site: https://jsonpath.com/ I can successfully retrieve the type of phone based on phone number:
JSON
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
Query
$.[?(@.number== '0123-4567-8888')].type
However I can't find any examples that show me how to match a partial search result. I'm trying to write a query where I provide just "0123" and hence get back both "home" and "iPhone" returned as results.How can I do this?
Upvotes: 1
Views: 711
Reputation: 168217
You can use =~
match filter operator which allows providing a regular expression instead of strict value so given you amend your query like:
$.phoneNumbers[?(@.number=~/.*0123.*/)].type
you will get both types as the result:
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios
Upvotes: 1