Rishabh Avvari
Rishabh Avvari

Reputation: 45

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

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

Upvotes: 0

Views: 340

Answers (2)

Saroar Zahan Sojib
Saroar Zahan Sojib

Reputation: 260

It's very simple. You can try this solution. I hope it will work for you.

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

Upvotes: 2

tomerar
tomerar

Reputation: 860

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)

Upvotes: 0

Related Questions