Skip to content

Instantly share code, notes, and snippets.

@keithweaver
Last active June 14, 2023 05:13
Show Gist options
  • Save keithweaver/ae3c96086d1c439a49896094b5a59ed0 to your computer and use it in GitHub Desktop.
Save keithweaver/ae3c96086d1c439a49896094b5a59ed0 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
@realsteel1104
Copy link

How to create a JSON file and save it to a specific folder?
I have created a JSON file but it gets saved in my project folder but I want to save it in another folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment