Last active
October 8, 2019 18:43
-
-
Save jps3/2d0252ec859d5c34d6bb0fe8f00b4d5f to your computer and use it in GitHub Desktop.
jq: select dicts containing sub-dicts containing a key "b"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"a": { | |
"b": { | |
"key_1": "value_1" | |
} | |
}, | |
"e": { | |
"b": { | |
"key_3": "value_3" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"a": { | |
"b": { | |
"key_1": "value_1" | |
}, | |
"c": { | |
"key_1": "value_1" | |
} | |
}, | |
"d": { | |
"a": { | |
"key_2": "value_2" | |
}, | |
"c": { | |
"key_2": "value_2" | |
} | |
}, | |
"e": { | |
"b": { | |
"key_3": "value_3" | |
}, | |
"c": { | |
"key_3": "value_3" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given valid JSON input file from colleague ... >:-/ | |
cat example-valid-input.json | jq '[ to_entries[] | select(.value.b) | { key: .key, value: {"b": .value.b} } ] | from_entries' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment