Created
July 10, 2016 15:24
-
-
Save zefirka/50f08b43a77fcc579c034dcea38c5c97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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