I have following JSON. I want to get key-value pair objects based on their role. In this example there are 3 roles(Presenter, Approver, Customer) but there can be more as it is dynamic.
JSON
{
"Presenter Name": "Roney",
"Presenter Email": "roney@domain.com",
"Approver Name": "Tim",
"Approver Email": "tim@domain.com",
"Customer Name": "Alex",
"Customer Email": "alex@domain.com",
"Invoice": "001",
"Date": "2022-02-14"
}
Expected output using jq, map,
{
"Presenter": {
"email_address": "roney@domain.com",
"name": "Roney",
"role": "Presenter"
},
"Approver": {
"email_address": "tim@domain.com",
"name": "Tim",
"role": "Approver"
},
"Customer": {
"email_address": "alex@domain.com",
"name": "Alex",
"role": "Customer"
}
}
I have tried till following but didn't get what to do next. Please advice.
to_entries |map( { (.key): { name: .value, email_address:.value, role: .key} } ) | add