MCPcopy Index your code
hub / github.com/clips/pattern / load

Function load

pattern/web/json/__init__.py:341–395  ·  view source on GitHub ↗

Deserialize ``fp`` (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. *encoding* determines the encoding used to interpret any :class:`str` objects decoded by this instance (``'utf-8'`` by default). It has no effect when decoding :class:`unic

(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
        parse_int=None, parse_constant=None, object_pairs_hook=None,
        use_decimal=False, namedtuple_as_object=True, tuple_as_array=True,
        **kw)

Source from the content-addressed store, hash-verified

339
340
341def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
342 parse_int=None, parse_constant=None, object_pairs_hook=None,
343 use_decimal=False, namedtuple_as_object=True, tuple_as_array=True,
344 **kw):
345 """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
346 a JSON document) to a Python object.
347
348 *encoding* determines the encoding used to interpret any
349 :class:`str` objects decoded by this instance (``'utf-8'`` by
350 default). It has no effect when decoding :class:`unicode` objects.
351
352 Note that currently only encodings that are a superset of ASCII work,
353 strings of other encodings should be passed in as :class:`unicode`.
354
355 *object_hook*, if specified, will be called with the result of every
356 JSON object decoded and its return value will be used in place of the
357 given :class:`dict`. This can be used to provide custom
358 deserializations (e.g. to support JSON-RPC class hinting).
359
360 *object_pairs_hook* is an optional function that will be called with
361 the result of any object literal decode with an ordered list of pairs.
362 The return value of *object_pairs_hook* will be used instead of the
363 :class:`dict`. This feature can be used to implement custom decoders
364 that rely on the order that the key and value pairs are decoded (for
365 example, :func:`collections.OrderedDict` will remember the order of
366 insertion). If *object_hook* is also defined, the *object_pairs_hook*
367 takes priority.
368
369 *parse_float*, if specified, will be called with the string of every
370 JSON float to be decoded. By default, this is equivalent to
371 ``float(num_str)``. This can be used to use another datatype or parser
372 for JSON floats (e.g. :class:`decimal.Decimal`).
373
374 *parse_int*, if specified, will be called with the string of every
375 JSON int to be decoded. By default, this is equivalent to
376 ``int(num_str)``. This can be used to use another datatype or parser
377 for JSON integers (e.g. :class:`float`).
378
379 *parse_constant*, if specified, will be called with one of the
380 following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This
381 can be used to raise an exception if invalid JSON numbers are
382 encountered.
383
384 If *use_decimal* is true (default: ``False``) then it implies
385 parse_float=decimal.Decimal for parity with ``dump``.
386
387 To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
388 kwarg.
389
390 """
391 return loads(fp.read(),
392 encoding=encoding, cls=cls, object_hook=object_hook,
393 parse_float=parse_float, parse_int=parse_int,
394 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
395 use_decimal=use_decimal, **kw)
396
397
398def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,

Callers

nothing calls this directly

Calls 2

loadsFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…