When i try to update my json file i get a error

Question:

When i try to update my json file i get this error:AttributeError: module ‘json’ has no attribute ‘update’ and I don’t understand why here is my code:

` with open(file="data.json", mode="r") as data_file: 
        data = json.load(data_file)
        json.update(new_data)
    with open(file="data.json", mode="w") as data_file:
        json.dump(data, data_file, indent=4)
        website.delete(0, t.END)
        password.delete(0, t.END)`
Asked By: Ace Ayan

||

Answers:

Replacing the third line (json.update(new_data)) with data.update(new_data) should fix your issue, assuming new_data is a dict.

Answered By: Bryce

The update is on the script "json" that is not a correct reference, replace it with "data.update"

Answered By: SaulCandia
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.