Filtering JSON based on key value using jq
Consider the following JSON with many resources:
{
"values": {
"root_module": {
"resources": [
...,
{
"address": "aws_iam_access_key.circleci",
"values": {
"id": "XXXXXXXXXXXX",
"secret": "XXXXXXXXXXXX"
}
},
...
]
}
}
}
Now you want to filter that json to only see values for objects with address equal to aws_iam_access_key.circleci
.
You can use jq
tool to do it:
DATA | jq '.values.root_module.resources | map(select(.address == "aws_iam_access_key.circleci"))'
DATA
can be sth like cat my.json
or in this particular example: terraform show -json
.