yajl.yajl_parse

Code that allows use of api/yajl_parse.h

exception yajl.yajl_parse.YajlParseCancelled

Bases: yajl.yajl_common.YajlError

class yajl.yajl_parse.YajlContentHandler

Bases: object

Subclass this Abstract Base Class and implement the callback routines that will be called by the YajlParser instance that you will pass an instance of the subclass (phew! did you get that?) to.

Note about handling of numbers (from yajl docs):

yajl will only convert numbers that can be represented in a double or a long long int. All other numbers will be passed to the client in string form using the yajl_number callback. Furthermore, if yajl_number is not NULL, it will always be used to return numbers, that is yajl_integer and yajl_double will be ignored. If yajl_number is NULL but one of yajl_integer or yajl_double are defined, parsing of a number larger than is representable in a double or long long int will result in a parse error.

Due to the above, implementing yajl_number() takes prescedence and the yajl_integer() & yajl_double() callbacks will be ignored. For this reason none of these three methods are enforced by the Abstract Base Class

Note all methods must accept a param ctx as the first argument, this is a yajl feature that is implemented in yajl-py but not very useful in python. see YajlParser.parse() for more info on ctx.

complete_parse()

Called when the parsing of the stream has finished

parse_buf()

Called when a complete buffer has been parsed from the stream

parse_start()

Called before each stream is parsed

yajl_boolean(ctx, boolVal)
yajl_end_array(ctx)
yajl_end_map(ctx)
yajl_map_key(ctx, stringVal)
yajl_null(ctx)
yajl_start_array(ctx)
yajl_start_map(ctx)
yajl_string(ctx, stringVal)
_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 26
_abc_registry = <_weakrefset.WeakSet object>
class yajl.yajl_parse.YajlParser(content_handler=None, buf_siz=65536, **kwargs)

Bases: object

A class that utilizes the Yajl C Library

Parameters:
  • content_handler (YajlContentHandler) – content handler instance hosting the callbacks that will be called while parsing.
  • buf_siz (int) – number of bytes to process from the input stream at a time (minimum 1)

To configure the parser you need to set attributes. Attribute names are similar to that of yajl names less the “yajl_” prefix, for example:

to enable yajl_allow_comments, set self.allow_comments=True
parse(f=<open file '<stdin>', mode 'r'>, ctx=None)

Function to parse a JSON stream.

Parameters:
  • f (file) – stream to parse JSON from
  • ctx (ctypes.POINTER) – passed to all callback functions as the first param this is a feature of yajl, and not very useful in yajl-py since the context is preserved using the content_handler instance.
Raises:

YajlError – When invalid JSON in input stream found

yajl_config(hand)
class yajl.yajl_parse.yajl_callbacks

Bases: _ctypes.Structure

_fields_ = [('yajl_null', <class 'ctypes.CFunctionType'>), ('yajl_boolean', <class 'ctypes.CFunctionType'>), ('yajl_integer', <class 'ctypes.CFunctionType'>), ('yajl_double', <class 'ctypes.CFunctionType'>), ('yajl_number', <class 'ctypes.CFunctionType'>), ('yajl_string', <class 'ctypes.CFunctionType'>), ('yajl_start_map', <class 'ctypes.CFunctionType'>), ('yajl_map_key', <class 'ctypes.CFunctionType'>), ('yajl_end_map', <class 'ctypes.CFunctionType'>), ('yajl_start_array', <class 'ctypes.CFunctionType'>), ('yajl_end_array', <class 'ctypes.CFunctionType'>)]
yajl_boolean

Structure/Union member

yajl_double

Structure/Union member

yajl_end_array

Structure/Union member

yajl_end_map

Structure/Union member

yajl_integer

Structure/Union member

yajl_map_key

Structure/Union member

yajl_null

Structure/Union member

yajl_number

Structure/Union member

yajl_start_array

Structure/Union member

yajl_start_map

Structure/Union member

yajl_string

Structure/Union member