I have following object:
{
"base": "/templates",
"title": "Templates",
"categories": {
"category1": {
"propertiesResources": {
"resources": {
"cliTemplate": {
"type": "CLIENT",
"path": "properties/cli.json",
"roles": [
"ROLE_SYSTEM_READ",
"ROLE_SYSTEM_WRITE"
]
},
"viewerTemplate": {
"type": "SERVER",
"path": "properties/server.json",
"roles": [
"ROLE_CONFIGURATOR_READ",
"ROLE_CONFIGURATOR_WRITE"
]
}
}
}
}
}
}
As you can see the field roles is an array which contains list of roles. The roles are guaranteed to be in this order. What I need is to replace the field roles with two new fields: roleRead and roleWrite where this new fields will have corresponding values from the array.
{
"base": "/templates",
"title": "Templates",
"categories": {
"category1": {
"propertiesResources": {
"resources": {
"cliTemplate": {
"type": "CLIENT",
"path": "properties/cli.json",
"readRole": "ROLE_SYSTEM_READ",
"writeRole": "ROLE_SYSTEM_WRITE"
},
"viewerTemplate": {
"type": "SERVER",
"path": "properties/server.json",
"readRole": "ROLE_CONFIGURATOR_READ",
"writeRole": "ROLE_CONFIGURATOR_WRITE"
}
}
}
}
}
}
Using this command I was able to get half way there
.categories[][].resources[].roles|={"readRole": .[0], "writeRole": .[1]}