1

我想编辑 Json 文件并在 json 文件中添加数据

这是我从 api 响应中获得的 json 文件-

{
    "options": [
        {
            "enabled": false,
            "definition": {
                "id": "hfjhj"
            },
            "inputs": {
                "branchFilters": "[\"+refs/heads/*\"]",
                "additionalFields": "{}"
            }
        },
        {
            "enabled": false,
            "definition": {
                "id": "hjhgj"
            },
            "inputs": {
                "workItemType": "Bug",
                "assignToRequestor": "true",
                "additionalFields": "{}"
            }
        }
    ],
    "variables": {
        "system.debug": {
            "value": "false",
            "allowOverride": true
        },
        "name": {
            "value": "myname"
        },
        "last_name": {
            "value": "my surname"
        }
    },

我想以相同的格式将其添加到上述 json 文件的变量部分中 -

"location": {
            "value": "my location"
        } 

我正在使用它来保存 json 文件 -

with open("tempfile.json", "w") as outfile:
    json.dump(data,outfile,indent=4)
    outfile.close()

我需要在此处添加什么代码才能在我的 json 文件中更新所需的 Json 数据?

4

0 回答 0