Skip to content Skip to sidebar Skip to footer

Jsonpath :contains Filter

Hey all, I was wondering if any knew of a way to use a regular expression or wildcard operator (or pehaps '%LIKE%' in SQL) so I could use JSONPath to do searching within a large se

Solution 1:

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.

Solution 2:

Also, may be it will be useful for someone. Link to JSONPath Notation

It works for me (JMeter 4.0)

=~

Match a JavaScript regular expression. For example, [?(@.description =~ /cat.*/i)] matches items whose description starts with cat (case-insensitive).

Solution 3:

If anyone wants the contains solution in Java then this works with JsonPath

Filter<?>filter= Filter.filter(Criteria.where("hey").regex(Pattern.compile(".*find.*")));
System.out.println(JsonPath.read(json, "$..[?]", filter));

Imports

import com.jayway.jsonpath.Criteria;
import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.JsonPath;

Solution 4:

=~ worked for me. Tested with Jmeter 5.3 JSON Extractor.

Post a Comment for "Jsonpath :contains Filter"