Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active May 7, 2019 00:32
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 raganmd/1d63092e5eb834692c7675b73b513673 to your computer and use it in GitHub Desktop.
Save raganmd/1d63092e5eb834692c7675b73b513673 to your computer and use it in GitHub Desktop.
import json
def write_dict_to_json(target_file, dict_to_save):
'''
A Helper function that writes JSON file to disk
Args
---------------
target_file (file path):
> a path to a .json file on disk. This is where the file will
> be written.
dict_to_save (dict):
> the dictionary to save as json.
Returns
---------------
None
'''
# open the json file
json_file = open(target_file, 'w')
# ensure the format for the json is human readable
pretty_json = json.dumps(dict_to_save, indent=4)
# write the json to file
json_file.write(pretty_json)
# close the file
json_file.close()
# example use
target_file = '{}/cues.json'.format(project.folder)
target_dict = {"presets": op('base_example').fetch('presets')}
write_dict_to_json(target_file, target_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment