Skip to content

Instantly share code, notes, and snippets.

@AdamMujtaba
Forked from keithweaver/save-file.py
Created January 26, 2018 16:17
Show Gist options
  • Save AdamMujtaba/8ac2b494f4ad78cd94b3d2a23ca30c8d to your computer and use it in GitHub Desktop.
Save AdamMujtaba/8ac2b494f4ad78cd94b3d2a23ca30c8d to your computer and use it in GitHub Desktop.
Save JSON file with Python
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