[Python] How to externalize JSON

Discussão em 'Python' iniciado por Stack, Agosto 14, 2025.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página