1

I want to edit Json file and add data in json file

Here is my json file I got from api response -

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

I want to add this in variables section in above json file in same format -

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

I am using this to save json file -

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

What code I need to add here to have required Json Data updated in my json file ?

megha
  • 621
  • 2
  • 11
  • 36
  • 1
    you can refer this answer: https://stackoverflow.com/a/13949837/10011503. Load the file contents, modify and then write back. – s.k Nov 25 '20 at 05:24

0 Answers0