Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Filter json to keep sub-content that matches a given pattern anywhere in the key or value

$
0
0

Suppose I have a json file. I want to filter this file to only output content where a given pattern appears in anywhere in the full path or leaf node value. For example, suppose the json file has below content:

{ "a": "foo", "b": "bar", "c": {  "d": "foo",  "e": "bar" }, "aa": {  "foo": [   1,   2,   3  ],  "bar": {   "foo": false  } }}

And the pattern is "foo". Then, the output should be as follows.

{ "a": "foo", "c": {  "d": "foo" }, "aa": {  "foo": [   1,   2,   3  ],  "bar": {   "foo": false  } }}

So, what should the jq command be?


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>