I have an application that generates data in this form:
[ {"metadata": {"labels": {"team": "eng" } },"spec": {"labels": {"instance_id": {"result": "x387j" },"another_field": {"result": "dfsf" } } } }, {"metadata": {"labels": {"team": "sre" } },"spec": {"labels": {"instance_id": {"result": "sd9f" } } } }]
Labels, here are the keys in .metadata.labels
and .spec.labels
.I can extract the labels as:
% jq -C ' .[] | ( .metadata.labels , .spec.labels ) | keys | .[] ' tmp/x.json | sort | uniq"instance_id""team"
I want to extract the label and result pairs as:
"team": "eng""instance_id": "x387j""another_field": "dfsf""team": "sre""instance_id": "sd9f"
I can get the objects in .metadata.labels, albiet in different form:
% jq -C '.[] | (.metadata.labels) ' tmp/x.json{"team": "eng"}{"team": "sre"}
generates one part, but here, I am not able to remove just the braces.The suggestion here, to remove brackets, quotes, and commasremoves the braces, but also the keys.
% jq -C '.[] | (.metadata.labels) | .[] ' tmp/x.json"eng""sre"
Also, I am then not able to figure out to get the objects in .spec.labels.