Jsonpath :Contains Filter

JSONPath :contains filter

nevermind, guys, found a way to do it by just using ECMA inside of JSONPath, though this is not a native selector / operator. Simply used:

$.[?(/find/.test(@.hey))]

the RegExp test( ) method (which JSONPath evals behind the scenes).

If anyone has a better answer, though, let me know.

JsonPath expression filtering based on "contains"?

Raw JSON Path doesn't do this, but depending on the implementation you're using, it might be supported.

We're currently in progress writing a formal specification. One of the open issues is the breadth of expression support we want. Feel free to add a comment. Once the spec is defined and published, I imagine most implementations will update to adhere.

jsonPath - how to filter results by matching substring

With regards to full value you can use a Filter Operator like:

$..[?(@.property2 =~ /misery.*?/i)].property2

Demo:

Sample Image

You can extract the 4-digit value out of the variable using Regular Expression Extractor


If you want to do this in one shot:

  1. Add JSR223 PostProcessor as a child of the request which returns above JSON
  2. Put the following code into "Script" area

    vars.put('misery', ((com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$..[?(@.property2 =~ /misery.*?/i)].property2').get(0) =~ ('(\\d+)'))[0][1]))
  3. Refer the extracted value as ${misery} where required

More information: Apache Groovy - Why and How You Should Use It

JSONPath - filter by field that name contain '@'

the easy way is replace the '@' character by it's hexadecimal code (\x40) directly into your jsonpath query:

$.media.track[?(@['\x40type']=="Audio")]

JSONPath filter property by value in object

It looks like JSONPath expressions applies only to arrays. See here and here. Your query $.queue[?(@.size>0)] works for:

{
"queue": [{
"size": 13
},
{
"size": 10
}]
}


Related Topics



Leave a reply



Submit