1

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?

ratsstack
  • 1,012
  • 4
  • 13
  • 32

1 Answers1

1

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:

enter image description here

More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Dmitri T
  • 159,985
  • 5
  • 83
  • 133