JSONPath:包含过滤器 [英] JSONPath :contains filter
问题描述
嘿所有,我想知道是否有人知道如何使用正则表达式或通配符运算符(或SQL中的pehaps '%LIKE%'
)所以我可以使用JSONPath在一大堆JSON数据中进行搜索。
例如(是的,我正在解析,而不是 eval()
在应用程序中输入我的数据):
var obj = eval('({hey: 你可以找到我吗? })' );
我希望能够查看这样的数据:
$。[?(@。hey:contains(find))] //(用jQuery术语)
其中参数的内容是 {key:value}中的部分或全部值
我的数据配对。
目前我只找到>
,<
, =
,!=
relational运营商,它没有给我这么大的灵活性。
有没有人知道我可以只是 JSONPath找到这些数据的方式(没有必须遍历所有条目)?
我不想使用Dojo的JSONQuery,因为这需要另一个库。但是,它允许你这样做,这里是他们的例子:
[?description〜'* the *']
问我是否想要更多澄清问题。
伙计们,通过在JSONPath中使用ECMA找到了一种方法,尽管这不是本机选择器/运算符。使用简单:
$。[?(/ find / .test(@。hey))]
RegExp test()方法(JSONPath eval
s幕后如果有人有更好的答案,请告诉我。
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 set of JSON data.
For instance (and yes, I'm parsing, not eval( )
ing my data in the app):
var obj = eval ( '({ "hey": "can you find me?" })' );
And I'd like to be able to look through the data like this:
$.[?(@.hey:contains(find))] // (in jQuery terminology)
where the contents of an argument is part or all of the value in the { "key" : "value" }
pairs in my data.
At the moment I have only found documentation on >
, <
, =
, and !=
relational operators, which don't give me that much flexibility.
Does anyone know a way I can just just JSONPath to find this data (without having to loop through all the entries)?
I don't want to use Dojo's JSONQuery, as this would require another library. However, it lets you do this, here their example:
[?description~‘*the*’]
Ask me if you want more clarification of the question.
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 eval
s behind the scenes).
If anyone has a better answer, though, let me know.
这篇关于JSONPath:包含过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!