改变python中dictonary列表的格式

时间:2018-02-20 17:46:32

标签: python-3.x

我有一个字典列表,我正在尝试通过添加几个额外的键来改进它,通过使用现有的键,但卡住了。

[
  {
    "middlewareName": "Tomcat",
    "middlewareId": 169935,    
    "dbName": "ORACLE",
    "dbId": 169938,  
    "storageId": 169933,
    "storageName": null,
    "applicationName": "payroll",
    "applicationId": 169933,
    "ID": 001
  },
  {
    "middlewareName": "WebSphere",
    "middlewareId": 169936,    
    "dbName": "ORACLE",
    "dbId": 169938,  
    "storageId": 169933,
    "storageName": null,
    "applicationName": "payroll",
    "applicationId": 169933,
    "ID": 8298
  }
]

我希望将其转换为以下格式。无法获得逻辑来操纵上述格式以获得下面的格式。需要帮助:

[{
  "applicationId": 3276,
  "applicationName": "Payroll",
  "middlewareList": [
    {
      "middlewareId": 12,
      "middlewareName": "ABC"
    },
    {
      "middlewareId": 121,
      "middlewareName": "AYC"
    }
  ],
  "dbList": [
    {
      "dbId": 12,
      "dbName": "ABC"
    },
    {
      "dbId": 121,
      "dbName": "AYC"
    }
  ],
  "storageList": [
    {
      "storageId": 12,
      "storageName": "ABC"
    },
    {
      "storageId": 121,
      "storageName": "AYC"
    }
  ]
}
]

怎么做?

0 个答案:

没有答案