I have JSON data stored in a file (Movies.json). i want to read the file and do some process and then save the output in new file
with open("Movies.json",'r') as f:
movies = json.loads(f.read())
// doing some process
How can i save the output?
Currently, I am trying this but it's not working:
json.dump(movies, f)
for output you need to use 'w' instead of 'r'
import json
# Opening JSON file
f = open('movies.json')
# returns JSON object as
# a dictionary
movies = json.load(f)
# Iterating through the json
# list
for i in movies:
print(i['id'])
# output
with open("Movies.json", 'w') as f:
json.dump(movies, f)
# Closing file
f.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With