我有以下 JSON。我想根据他们的角色获取键值对对象。在此示例中,有 3 个角色(Presenter、Approver、Customer),但可以有更多,因为它是动态的。
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"
}
使用 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"
}
}
我已经尝试过,但没有得到下一步该做什么。请指教。
to_entries |map( { (.key): { name: .value, email_address:.value, role: .key} } ) | add