查找以JSON Path开头的JSON属性名称 [英] Find a JSON property name that starts with something using JSON Path

查看:253
本文介绍了查找以JSON Path开头的JSON属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JSON Path找到与正则表达式模式(或至少以其开头)匹配的属性名称。在XPath中我可以使用 name()但是我找不到等效的JSON路径

Is it possible to find a property name that matches a regex pattern (or at least starts with) using JSON Path. In XPath I can use name() but I haven't been able to find the JSON Path equivalent.

基本上,我找到所有以 x开头的属性名称 - 。类似 $ .. x - *

Basically, I what to find all property names that start with x-. Something like $..x-*.

我有兴趣使用任何 javascript包这样做。目前,我正在使用 JSONPath

I'll be interested in using any javascript package that does this. Currently, I'm using JSONPath.

推荐答案

从我的谷歌搜索中,这在标准 json路径中是不可能的。但是, JSONPath 软件包使用 @path ;并使以下成为可能

From my googling this is not possible in standard json path. However, the JSONPath package extends the specification with @path; and makes the following possible

$..[?(@path.includes("[\'x-"))]

以上假设您使用的是 ES6

这篇关于查找以JSON Path开头的JSON属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆