store_json

Takes in a json-portable object and a filesystem-based destination and stores
the json-portable object as JSON into the filesystem-based destination.

This is blind, dumb, and stupid; thus, it can fail if the object is more
complex than simple dict, list, int, str, etc. type object structures.

def store_json(obj, destination):
    """store_json

Takes in a json-portable object and a filesystem-based destination and stores
the json-portable object as JSON into the filesystem-based destination.

This is blind, dumb, and stupid; thus, it can fail if the object is more
complex than simple dict, list, int, str, etc. type object structures.
    """
    with open(destination, 'r+') as FH:
        fcntl.lockf(FH, fcntl.LOCK_EX)
        json_in = json.loads(FH.read())
        json_in.update(obj)  # obj overwrites items in json_in...
        FH.seek(0)
        FH.write(json.dumps(json_in, sort_keys=True, indent=4,
                            separators=(',', ': ')))