Json path to find all objects having the particular property

Viewed 59

It seems that it is a trivial task for the "JSON path" language but I cannot solve it properly. To test my attempts I use https://jsonpath.com/ and Newtonsoft.NET library.

I have a very simple JSON:

{"config":{"id":"id1","key":"k1"},"external":{"config":{"key":"k2"}}}

And I want to find all "config" objects that have the property "id" presented. I thoght the query $..config[?(@.id)] should work but it doesn't.

The query $..[?(@.id)] works for my example but in the general case, it's obviously not exactly what I want.

Also, the first query works for a little bit another JSON:

{"config":[{"id":"id1","key":"k1"}],"external":{"config":[{"key":"k2"}]}}

but, again, that's not strictly what I need.

Could you, please, show me the error in my reasoning and the correct JSON path query exactly matching my needs?

0 Answers
Related