Answers for "modify json file python"

8

save json file python

with open('data.txt', 'w') as outfile:
    json.dump(data, outfile)
Posted by: Guest on July-28-2020
3

edit json file python

import json

with open('data.json', 'r+') as f:
    data = json.load(f)
    data['id'] = 134 # <--- add `id` value.
    f.seek(0)        # <--- should reset file position to the beginning.
    json.dump(data, f, indent=4)
    f.truncate()     # remove remaining part
Posted by: Guest on December-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language