Skip to content

Instantly share code, notes, and snippets.

@raganmd
Last active September 3, 2021 19:05
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/8dc54f6cea0d2cefe35614722c98d9f1 to your computer and use it in GitHub Desktop.
Save raganmd/8dc54f6cea0d2cefe35614722c98d9f1 to your computer and use it in GitHub Desktop.
td-json-handler.py
import json
def Json_to_dict(json_file):
'''converts json to a python dictionary
'''
with open(json_file, 'r') as target_file:
json_dict = json.load(target_file)
return json_dict
def Save_dict_to_json(input_dict, json_file):
'''saves a python dictionary to json
'''
with open(json_file, 'w') as targe_file:
dict_to_json = json.dumps(input_dict, indent=4, sort_keys=True )
targe_file.write(dict_to_json)
def Save_storage_to_json(storage_dict, json_file):
'''saves dictionary to json
'''
with open(json_file, 'w') as target_file:
dict_to_json = json.dumps(storage_dict, indent=4, sort_keys=True )
target_file.write(dict_to_json)
pass
def Load_json_to_storage(target_op, json_file):
'''loads json file into storage
'''
with open(json_file, 'r') as target_file:
for each_key, each_dict in json.load(target_file).items():
target_op.store(each_key, each_dict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment