Skip to content

Instantly share code, notes, and snippets.

@zefirka
Created July 10, 2016 15:24
Show Gist options
  • Save zefirka/50f08b43a77fcc579c034dcea38c5c97 to your computer and use it in GitHub Desktop.
Save zefirka/50f08b43a77fcc579c034dcea38c5c97 to your computer and use it in GitHub Desktop.
import json
import utils
def read_json(filename):
with open(filename, 'r') as jsonfile:
content = jsonfile.read()
return json.loads(content)
def write_json(filename, struct):
with open(filename, 'w+') as jsonfile:
content = json.dumps(struct)
jsonfile.write(content)
def update_json_list(filename, dict):
struct = read_json(filename)
if type(struct) != list:
raise Exception('{0} is not a list'.format(filename))
struct.append(dict)
write_json(filename, struct)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment