JSONPath :contains filter

别来无恙 提交于 2019-11-29 06:38:57

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.

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).

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!