Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ContentHandler(YajlContentHandler):
- def __init__(self):
- self.out = sys.stdout
- self.json_list = []
- self.json_object = {}
- self.key, self.val = '', ''
- pass
- def yajl_null(self, ctx):
- pass
- def yajl_boolean(self, ctx, boolVal):
- pass
- def yajl_integer(self, ctx, integerVal):
- self.out.write(integerVal)
- pass
- def yajl_double(self, ctx, doubleVal):
- self.out.write(doubleVal)
- pass
- def yajl_number(self, ctx, stringNum):
- stringNum = stringNum.decode('utf-8')
- num = float(stringNum) if '.' in stringNum else int(stringNum)
- self.json_object[self.key.decode('utf-8')] = num
- pass
- def yajl_string(self, ctx, stringVal):
- self.json_object[self.key.decode('utf-8')] = stringVal.decode('utf-8')
- pass
- def yajl_start_map(self, ctx):
- pass
- def yajl_map_key(self, ctx, stringVal):
- self.key = stringVal
- pass
- def yajl_end_map(self, ctx):
- self.json_list.append(self.json_object)
- self.json_object = {}
- pass
- def yajl_start_array(self, ctx):
- self.json_list = []
- pass
- def yajl_end_array(self, ctx):
- pass
- obj = ContentHandler() # the class with callback methods to store json into object
- parser = YajlParser(obj)
- f = gzip.open(json_file, 'rb')
- parser.parse(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement