-
-
Save bantya/57c1a9f4b2714b1c85db29c04b4d272a to your computer and use it in GitHub Desktop.
Save JSON file with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def writeToJSONFile(path, fileName, data): | |
filePathNameWExt = './' + path + '/' + fileName + '.json' | |
with open(filePathNameWExt, 'w') as fp: | |
json.dump(data, fp) | |
# Example | |
data = {} | |
data['key'] = 'value' | |
writeToJSONFile('./','file-name',data) | |
# './' represents the current directory so the directory save-file.py is in | |
# 'test' is my file name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment