Skip to content Skip to sidebar Skip to footer

Dump Python Dictionary To Json File

I want to dump data that i scrapped into a json file. I believe it already is in a good format (dictionary, list, string, etc.) How can I output into a json file? #!/usr/bin/python

Solution 1:

You need to use the following:

withopen('output.json', 'w') as jsonFile:
    json.dump(scrapedData, jsonFile)

Where is going to write the dictionary to the output.json file in the working directory. You can provide full path like open('C:\Users\user\Desktop\output.json', 'w') instead of open('output.json', 'w') for example to output the file to the user's Desktop.

Post a Comment for "Dump Python Dictionary To Json File"