load() function

rapidjson.load(stream, *, object_hook=None, number_mode=None, datetime_mode=None, uuid_mode=None, parse_mode=None, chunk_size=65536, allow_nan=True)

Decode the given Python file-like stream containing a JSON formatted value into Python object.

Parameters
  • stream – a file-like object

  • object_hook (callable) – an optional function that will be called with the result of any object literal decoded (a dict) and should return the value to use instead of the dict

  • number_mode (int) – enable particular behaviors in handling numbers

  • datetime_mode (int) – how should datetime and date instances be handled

  • uuid_mode (int) – how should UUID instances be handled

  • parse_mode (int) – whether the parser should allow non-standard JSON extensions

  • chunk_size (int) – read the stream in chunks of this size at a time

  • allow_nan (bool) – compatibility flag equivalent to number_mode=NM_NAN

Returns

An equivalent Python object.

Raises
  • ValueError – if an invalid argument is given

  • JSONDecodeError – if string is not a valid JSON value

The function has the same behaviour as loads(), except for the kind of the first argument that is expected to be file-like object instead of a string:

>>> load(io.StringIO('"Naïve"'))
'Naïve'
>>> load(io.BytesIO(b'["string", {"kind": "object"}, 3.14159]'))
['string', {'kind': 'object'}, 3.14159]

chunk_size

The chunk_size argument determines the size of the buffer used to load the stream: the greater the value, the fewer calls will be made to its read() method.

Consult the loads() documentation for details on all other arguments.