BMW BMW - 4 months ago 23
JSON Question

How to make it work with filter in jq

I'd like to filter output from below json file to get all start with "tag_Name"


"tag_Name_abc": [
"tag_Name_efg": [



Try something but failed.

$ cat output.json |jq 'map(select(startswith("tag_Name")))'
jq: error (at <stdin>:1466): startswith() requires string inputs

Answer Source

There's plenty of ways you can do this but the simplest way you can do so is to convert that object to entries so you can get access to the keys, then filter the entries by the names you want then back again.

with_entries(select(.key | startswith("tag_Name")))