Quantcast
Viewing all articles
Browse latest Browse all 14069

Edit JSON item from file

I have the following code:

import jsonwith open("prefix.json", 'r+') as f:    data = json.load(f)def changeprefix(id, prefix):    global data    if not id in data:        json.dump(data, open("prefix.json", "w"), indent = 4)        data[id] = prefix    else:        # Code to edit existing itemchangeprefix("6", "?")

It opens a file named prefix.json and I want to be able to edit an existing item, for example:

{"item": "234"}

How can I change item to something else, for example to text here, then save the file?


Viewing all articles
Browse latest Browse all 14069

Trending Articles