Find a JSON property name that starts with something using JSON Path

Is it possible to find a name property that matches the regular expression pattern (or at least starts with) using the JSON Path. In XPath I can use name(), but I could not find the equivalent of the JSON Path .

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

I will be interested to use any javascript package that will do this. I am currently using JSONPath .

+4
source share
2 answers

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-"))]

The above assumes you are using ES6 .

+2
source

Useful for someone else.
You can use regex using regex = ~ left. For more information, visit https://github.com/jayway/JsonPath

[?(@.name =~ /foo.*?/i)]
0
source

Source: https://habr.com/ru/post/1617566/


All Articles