Example #1
0
def convert_to_json(buffer, name):
    ""
    try:
        if buffer.endswith(constants.postfix):
            buffer = buffer[:-len(constants.postfix)].decode(
                'utf-8')  # slice 'end' off
        json_data = json.loads(buffer)
    except json.JSONDecodeError as e:
        raise exceptions.JSONParseError(
            buffer, name, "Failed parsing json data: {}".format(e))
    return json_data
Example #2
0
def convert_to_json(buffer, name, log=log):
    ""
    try:
        log.d("Converting", sys.getsizeof(buffer), "bytes to JSON")
        if buffer.endswith(constants.postfix):
            buffer = buffer[:-len(constants.postfix)]  # slice eof mark off
        if isinstance(buffer, bytes):
            buffer = buffer.decode('utf-8')
        json_data = json.loads(buffer)
    except json.JSONDecodeError as e:
        raise exceptions.JSONParseError(
            buffer, name, "Failed parsing JSON data: {}".format(e))
    if constants.dev:
        log.d("data:\n", json_data)
    return json_data