Current output from script.
{
"entities": [
{
"chuck123": {
"type": "barebone",
"data": {
"customer_name": "Batman",
"subdomain": "Gotham",
"console": "radio",
"portal_url": "blue",
"subdomain_partner": "Bking",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "bridge",
"operating_system": "ubuntu"
}
}
},
{
"sam123": {
"type": "barebone",
"data": {
"customer_name": "Robin",
"subdomain": "Circus",
"console": "radio",
"portal_url": "purple",
"subdomain_partner": "BurgerNFries",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "carbank",
"operating_system": "debian"
}
}
}
]
}
Perferred Format - I am trying to move the object up one layer.
{
"entities": {
"chuck123": {
"type": "barebone",
"data": {
"customer_name": "Batman",
"subdomain": "Gotham",
"console": "radio",
"portal_url": "blue",
"subdomain_partner": "Bking",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "bridge",
"operating_system": "ubuntu"
}
},
"sam123": {
"type": "barebone",
"data": {
"customer_name": "Robin",
"subdomain": "Circus",
"console": "radio",
"portal_url": "purple",
"subdomain_partner": "BurgerNFries",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "carbank",
"operating_system": "debian"
}
}
}
}
I could definitely use some help. Been trying every combination I can think of to alter the output up one layer without any success. I've tried jq and jtc and am most likely overthinking it. Appreciate any assistance others can provide.
CodePudding user response:
If you're looking for a solution using jq, then it should be just updating the entities array using add:
jq '.entities |= add' input.json
{
"entities": {
"chuck123": {
"type": "barebone",
"data": {
"customer_name": "Batman",
"subdomain": "Gotham",
"console": "radio",
"portal_url": "blue",
"subdomain_partner": "Bking",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "bridge",
"operating_system": "ubuntu"
}
},
"sam123": {
"type": "barebone",
"data": {
"customer_name": "Robin",
"subdomain": "Circus",
"console": "radio",
"portal_url": "purple",
"subdomain_partner": "BurgerNFries",
"platform": "arch",
"group": "DC Squad",
"endpoint_type": "carbank",
"operating_system": "debian"
}
}
}
}
