I have the following JSON in my view (simplified for this example):
video =
{
'label': 'hd',
'url': 'google',
'format': 'mp4',
'video_codec': 'h264',
'audio_codec': 'aac',
'size': '1080x720',
}
And I can call a function like so: do_something(video)
However, when I try and extract this JSON into an external file, as follows —
file=open('data.json')
video=file.read()
I get an error, which appears to be related to having newlines and excessive spaces in the file. How would I 1) format the above json document to put it into an external file; and 2) how would I import it so I can use it with a function? Thank you.
It’s easy once you have actual JSON, preferably from
json.dump().