Skip to content

Instantly share code, notes, and snippets.

@Admin9705
Forked from keithweaver/save-file.py
Created October 25, 2018 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Admin9705/8bed170f4afb8fd76ac38579371fe348 to your computer and use it in GitHub Desktop.
Save Admin9705/8bed170f4afb8fd76ac38579371fe348 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