I have following JSON. I want to get key-value pair objects based on their CC role. In this example there are 3 roles(Presenter, Approver, Customer). Presenter is of type TO. Other 2 are of type CC. I want to get of type CC. There can be more as it is dynamic.
JSON
{
"Presenter_TO_Email": "[email protected]",
"Approver_CC_Email": "[email protected]",
"Customer_CC_Email": "[email protected]",
"Invoice": "001",
"Date": "2022-02-14"
}
Output
{
"Approver": {
"email_address": "[email protected]",
"role": "Approver"
},
"Customer": {
"email_address": "[email protected]",
"role": "Customer"
}
}
I can do using INDEX using this example but as I am using older version of jq, it throws error jq: error: INDEX/2 is not defined at <top-level>, line 1:
Use
with_entriesto make changes based on keys and values:Demo