需要帮助格式化 json 输出,提升对象中的对象

Need assistance formatting json output, lifting an object within an object

脚本的当前输出。

    {
      "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"
            }
          }
        }
      ]
    }

首选格式 - 我正在尝试将对象向上移动一层。

{
  "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"
        }
      }
   }
}

我绝对需要一些帮助。一直在尝试我能想到的每一种组合来改变输出一层,但没有成功。我已经尝试过 jq 和 jtc 并且很可能想得太多了。感谢他人提供的任何帮助。

如果您正在寻找使用 jq 的解决方案,那么它应该只是使用 add:

更新 entities 数组
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"
      }
    }
  }
}

Demo