The start of a Blitzorg data parser. Read an unzipped file from Bzorg,
    into a json object retrieved with .get_data().
327387
def blitz_parser():
    
    with gzip.open('tmp_data/bz-2015-02-01-06-30.json.gz', 'rb') as f:
        file_content = f.read()
    tx = file_content.strip()
    k = tx.decode(encoding='utf-8')
    print("{0} elements in k list".format(len(k.split())))
    j = json.loads(k.split()[0])  # example of decoding an element to json
    return
600675
def from_data(cls, data):
        
        obj = cls()
        with contextlib.closing(BytesIO(data)) as file_handle:
            obj.load_file(file_handle)
        return obj
1078891
def load_json_object(file_name, default=None):
    
    if not os.path.isfile(file_name):
        return default

    # use utf-8-sig in case the file has a Byte Order Mark
    with codecs.open(file_name, 'r', 'utf-8-sig') as in_file:
        # read the text from the file
        content = in_file.read()

    # convert Windows line endings to Linux line endings
    content = content.replace('\r\n', '\n')

    # return a deserialized object
    return json.loads(content)
158003
def read_json(location):
    
    location = ensure_path(location)
    with location.open('r', encoding='utf8') as f:
        return ujson.load(f)
789814
def parse(self, data, mimetype):
        
        encoding = mimetype.params.get('charset') or 'utf-8'

        return json.loads(data.decode(encoding))
994159
def read(path, create_file=False):
        
        if create_file:
            with open(str(path), 'a+') as data_file:
                data_file.seek(0)
                return json.load(data_file)

        else:
            with open(str(path)) as data_file:
                return json.load(data_file)
277000
def read_json(file_or_path):
    """"""
    try:
        with (open(file_or_path, 'r') if isinstance(file_or_path, (str, bytes)) else file_or_path) as f:
            obj = json.load(f)
    except IOError:
        obj = json.loads(file_or_path)
    return obj
154823
def load_json(file, new_root_dir=None, decompression=False):
    """"""
    if decompression:
        with open(file, 'rb') as f:
            my_object = load(f, decompression=decompression)
    else:
        with open(file, 'r') as f:
            my_object = load(f, decompression=decompression)
    if new_root_dir:
        my_object.root_dir = new_root_dir

    return my_object
661397
def load_json(path: str, encoding: str = "utf-8") -> HistogramBase:
    """"""
    with open(path, "r", encoding=encoding) as f:
        text = f.read()
        return parse_json(text)
607526
def read_from_json(json_filename):
  """"""
  with tf.io.gfile.GFile(json_filename) as f:
    dataset_info_json_str = f.read()
  # Parse it back into a proto.
  parsed_proto = json_format.Parse(dataset_info_json_str,
                                   dataset_info_pb2.DatasetInfo())
  return parsed_proto
1275461
def load_from_json(data):
        
        if isinstance(data, str):
            data = json.loads(data)
        return Item(data['title'], data['uri'])
925391
def __parse(self) -> object:
        """"""
        char = self.data[self.idx: self.idx + 1]
        if char in [b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'0']:
            str_len = int(self.__read_to(b':'))
            return self.__read(str_len)
        elif char == b'i':
            self.idx += 1
            return int(self.__read_to(b'e'))
        elif char == b'd':
            return self.__parse_dict()
        elif char == b'l':
            return self.__parse_list()
        elif char == b'':
            raise bencodepy.DecodingError('Unexpected End of File at index position of {0}.'.format(str(self.idx)))
        else:
            raise bencodepy.DecodingError(
                'Invalid token character ({0}) at position {1}.'.format(str(char), str(self.idx)))
1073813
def get_dict_from_json_file(path, encoding='utf-8'):
    
    with open(path, encoding=encoding) as data_file:
        return json.loads(data_file.read())
531910
def decode(data):
    
    decoded = None
    try:
        decoded = json.loads(data)
    except Exception, e:
        raise MetaParsingException("Can't parse your JSON data: %s" % e.message)

    decoded = validator.check_structure(decoded)

    return decoded
1242158
def load_json(data=None, path=None, name='NT'):
    
    if data and not path:
        return mapper(json.loads(data), _nt_name=name)
    if path and not data:
        return mapper(json.load(path), _nt_name=name)
    if data and path:
        raise ValueError('expected one source and received two')
1293130
def json_decode(data):
    
    if isinstance(data, six.binary_type):
        data = data.decode('utf-8')

    return json.loads(data)
642973
def read_json_breakdown(cls, fname):
        """"""
        if not os.path.exists(fname):
            raise RuntimeError

        with open(fname, 'r') as data_file:
            return cls.fixup_from_json(data_file.read())