Parses a textfile using json to build a python object representation
764588
def json_decode_file(filename):
    
    seq = open(filename).read()
    # The JSON standard has no comments syntax. We have to remove them
    # before feeding python's JSON parser
    seq = json_remove_comments(seq)
    # Parse all the unicode stuff to utf-8
    return json_unicode_to_utf8(json.loads(seq))
121787
def fromJSON(value):
        
        j = json.loads(value)
        v = GPDataFile()
        if "defaultValue" in j:
            v.value = j['defaultValue']
        else:
            v.value = j['value']
        if 'paramName' in j:
            v.paramName = j['paramName']
        elif 'name' in j:
            v.paramName = j['name']
        return v
349031
def _parser_jsonip(text):
    """"""
    import json
    try:
        return str(json.loads(text).get("ip"))
    except ValueError as exc:
        LOG.debug("Text '%s' could not be parsed", exc_info=exc)
        return None
300350
def parse_json(json_file, include_date=False):
    
    if json_file[-2:] == 'gz':
        fh = gzip.open(json_file, 'rt')
    else:
        fh = io.open(json_file, mode='rt', encoding='utf8')
    for line in fh:
        try:
            jj = json.loads(line)
            if type(jj) is not list:
                jj = [jj]
            for j in jj:
                if include_date:
                    yield (j['user']['screen_name'].lower(), j['text'], j['created_at'])
                else:
                    if 'full_text' in j: # get untruncated text if available.
                        yield (j['user']['screen_name'].lower(), j['full_text'])
                    else:
                        yield (j['user']['screen_name'].lower(), j['text'])

        except Exception as e:
            sys.stderr.write('skipping json error: %s\n' % e)
173664
def load_json(filename):
    """"""
    try:
        if PY2:
            args = 'rb'
        else:
            args = 'r'
        with open(filename, args) as fid:
            data = json.load(fid)
        return data, None
    except Exception as err:
        return None, str(err)
884667
def _ParseFile(self, file_obj, line_parser):
    
    lines = [
        l.strip() for l in utils.ReadFileBytesAsUnicode(file_obj).splitlines()
    ]
    try:
      for index, line in enumerate(lines):
        if line:
          line_parser(line)
    except (IndexError, KeyError) as e:
      raise parser.ParseError("Invalid file at line %d: %s" % (index + 1, e))
1366907
def _parse_object_list(self):
        """"""
        array = []

        indent = 0
        while not self._finished:
            self._skip_newlines()
            if self._cur_token['type'] is TT.ws:
                while self._cur_token['type'] is TT.ws:
                    indent = self._skip_whitespace()
                    self._skip_newlines()
            elif self._cur_token['type'] is TT.id:
                array.append(self._parse_key(indent))
            elif self._cur_token['type'] is TT.hyphen:
                self._increment()
                if self._cur_token['type'] is not TT.hyphen or self._finished:
                    return array
                else:
                    self._increment()
            else:
                raise ParseError('something different', self._cur_token)
254712
def object_to_json(obj, indent=2):
    
    instance_json = json.dumps(obj, indent=indent, ensure_ascii=False, cls=DjangoJSONEncoder)
    return instance_json
756828
def __parse_json_file(self, file_path):
        
        if file_path == '' or os.path.splitext(file_path)[1] != '.json':
            raise IOError('Invalid Json file')

        with open(file_path) as json_file:
            self._raw_data = json.load(json_file)

        self._json_data = copy.deepcopy(self._raw_data)
1083731
def from_json_and_lambdas(cls, file: str, lambdas):
        
        with open(file, "r") as f:
            data = json.load(f)

        return cls.from_dict(data, lambdas)
194384
def parse_json(path):
    # type: (str) -> List[FunctionInfo]
    
    with open(path) as f:
        data = json.load(f)  # type: List[RawEntry]
    result = []

    def assert_type(value, typ):
        # type: (object, type) -> None
        assert isinstance(value, typ), '%s: Unexpected type %r' % (path, type(value).__name__)

    def assert_dict_item(dictionary, key, typ):
        # type: (Mapping[Any, Any], str, type) -> None
        assert key in dictionary, '%s: Missing dictionary key %r' % (path, key)
        value = dictionary[key]
        assert isinstance(value, typ), '%s: Unexpected type %r for key %r' % (
            path, type(value).__name__, key)

    assert_type(data, list)
    for item in data:
        assert_type(item, dict)
        assert_dict_item(item, 'path', Text)
        assert_dict_item(item, 'line', int)
        assert_dict_item(item, 'func_name', Text)
        assert_dict_item(item, 'type_comments', list)
        for comment in item['type_comments']:
            assert_type(comment, Text)
        assert_type(item['samples'], int)
        info = FunctionInfo(encode(item['path']),
                            item['line'],
                            encode(item['func_name']),
                            [encode(comment) for comment in item['type_comments']],
                            item['samples'])
        result.append(info)
    return result
736122
def _schema_from_json_file_object(self, file_obj):
        
        json_data = json.load(file_obj)
        return [SchemaField.from_api_repr(field) for field in json_data]
1242147
def parse_json(json_file):
    
    if not os.path.exists(json_file):
        return None

    try:
        with open(json_file, "r") as f:
            info_str = f.readlines()
            info_str = "".join(info_str)
            json_info = json.loads(info_str)
            return unicode2str(json_info)
    except BaseException as e:
        logging.error(e.message)
        return None
212319
def parse_text(text: str, schema: dict) -> Any:
    
    try:
        data = json.loads(text)
        jsonschema.validate(data, schema)
    except (TypeError, json.decoder.JSONDecodeError):
        raise jsonschema.ValidationError("Could not parse json")

    return data
988837
def _parse_json_with_fieldnames(self):
        
        for key in dir(self):
            if not key.startswith('_') and key not in self._TO_EXCLUDE:
                self.fieldnames.append(key)
                value = getattr(self, key)
                if value:
                    self.json[key] = value
        # Add OK attribute even if value is "False"
        self.json['ok'] = self.ok
298191
def read_json(fn):
    
    with open(fn) as f:
        return json.load(f, object_hook=_operator_object_hook)
586755
def parse_text_to_dict(self, txt):
        
        op = {}
        print('TODO - import NLP, split into verbs / nouns')
        op['nouns'] = txt
        op['verbs'] = txt
        
        return op