Home > Mobile >  How to update a part of data in a json file using python
How to update a part of data in a json file using python

Time:02-02

I want to update only a part of data in this json file and im struggling to do it.

the json file is as follows:

[
    {
        "IP": "Not Specified",
        "MOTD": "Not Specified",
        "Seed": "Not Specified",
        "Server_image": "Not Specified",
        "Cracked_status": "Not Specified",
        "Version": "Not Specified",
        "Software": "Not Specified",
        "Difficulty": "Not Specified"
    }
]

I want to update the IP value using python

xd.txt 1 KB

CodePudding user response:

it's very simple. you can try this concept. i hope it will work for you.

list_name[0]["IP"]="here will be the update value"

CodePudding user response:

the easy way to convert to dict modify and convert to JSON

import json


json_t = '[{"IP":"Not Specified","MOTD":"Not Specified","Seed":"Not Specified","Server_image":"Not Specified","Cracked_status":"Not Specified","Version":"Not Specified","Software":"Not Specified","Difficulty":"Not Specified"}]'
list_t = json.loads(json_t)
# modify the dict
json_t = json.dumps(list_t)

  •  Tags:  
  • Related