I am struggling to get formatted output from an aws dynamodb scan command. An item in the dynamodb table looks like below:
{
"labels": {
"Category": [
"Data",
"EMR"
],
"Environment": "NonProd",
"Severity": "Critical"
},
"subscriber_id": "blah@blah.com",
"subscriber_type": "email"
}
When I run the query:
aws dynamodb scan --table-name dummy_table --region region_name --
profile default --query "Items[?subscriber_id.S ==
'blah@blah.com'].labels.M[]"
I get the output as below:
[
{
"Environment": {
"S": "NonProd"
},
"Severity": {
"S": "Critical"
},
"Category": {
"L": [
{
"S": "Data"
},
{
"S": "EMR"
}
]
}
}
]
Desired output is:
{
"Category": [
"Data",
"EMR"
],
"Environment": "NonProd",
"Severity": "Critical"
}
To achieve the desired output, I tried to manipulate using jq.
Updated query:
aws dynamodb scan --table-name dummy_table --region
region_name --
profile default --query "Items[?subscriber_id.S ==
'blah@blah.com'].labels.M[]" |
jq -r '.[]
| to_entries[]
| [{key:.key, value:.value[]}]
| from_entries' | jq -s add
Output is:
{
"Environment": "NonProd",
"Severity": "Critical",
"Category": [
{
"S": "Data"
},
{
"S": "EMR"
}
]
}
As you see it's close, but it's not processing the Category list. Any help with getting the desired output is appreciated.
Thanks