OpenQuizz
Une application de gestion des contenus pédagogiques
bson.json_util Namespace Reference

Data Structures

class  DatetimeRepresentation
 
class  JSONMode
 
class  JSONOptions
 

Functions

def dumps (obj, *args, **kwargs)
 
def loads (s, *args, **kwargs)
 
def object_pairs_hook (pairs, json_options=DEFAULT_JSON_OPTIONS)
 
def object_hook (dct, json_options=DEFAULT_JSON_OPTIONS)
 
def default (obj, json_options=DEFAULT_JSON_OPTIONS)
 

Variables

 LEGACY_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.LEGACY)
 
 DEFAULT_JSON_OPTIONS = LEGACY_JSON_OPTIONS
 
 CANONICAL_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.CANONICAL)
 
 RELAXED_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.RELAXED)
 
 STRICT_JSON_OPTIONS
 

Function Documentation

◆ default()

def bson.json_util.default (   obj,
  json_options = DEFAULT_JSON_OPTIONS 
)

◆ dumps()

def bson.json_util.dumps (   obj,
args,
**  kwargs 
)
Helper function that wraps :func:`json.dumps`.

Recursive function that handles all BSON types including
:class:`~bson.binary.Binary` and :class:`~bson.code.Code`.

:Parameters:
  - `json_options`: A :class:`JSONOptions` instance used to modify the
    encoding of MongoDB Extended JSON types. Defaults to
    :const:`DEFAULT_JSON_OPTIONS`.

.. versionchanged:: 3.4
   Accepts optional parameter `json_options`. See :class:`JSONOptions`.

.. versionchanged:: 2.7
   Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
   instances.

◆ loads()

def bson.json_util.loads (   s,
args,
**  kwargs 
)
Helper function that wraps :func:`json.loads`.

Automatically passes the object_hook for BSON type conversion.

Raises ``TypeError``, ``ValueError``, ``KeyError``, or
:exc:`~bson.errors.InvalidId` on invalid MongoDB Extended JSON.

:Parameters:
  - `json_options`: A :class:`JSONOptions` instance used to modify the
    decoding of MongoDB Extended JSON types. Defaults to
    :const:`DEFAULT_JSON_OPTIONS`.

.. versionchanged:: 3.5
   Parses Relaxed and Canonical Extended JSON as well as PyMongo's legacy
   format. Now raises ``TypeError`` or ``ValueError`` when parsing JSON
   type wrappers with values of the wrong type or any extra keys.

.. versionchanged:: 3.4
   Accepts optional parameter `json_options`. See :class:`JSONOptions`.

◆ object_hook()

def bson.json_util.object_hook (   dct,
  json_options = DEFAULT_JSON_OPTIONS 
)

◆ object_pairs_hook()

def bson.json_util.object_pairs_hook (   pairs,
  json_options = DEFAULT_JSON_OPTIONS 
)

Variable Documentation

◆ CANONICAL_JSON_OPTIONS

CANONICAL_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.CANONICAL)

◆ DEFAULT_JSON_OPTIONS

DEFAULT_JSON_OPTIONS = LEGACY_JSON_OPTIONS

◆ LEGACY_JSON_OPTIONS

LEGACY_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.LEGACY)

◆ RELAXED_JSON_OPTIONS

RELAXED_JSON_OPTIONS = JSONOptions(json_mode=JSONMode.RELAXED)

◆ STRICT_JSON_OPTIONS

STRICT_JSON_OPTIONS
Initial value:
1 = JSONOptions(
2  strict_number_long=True,
3  datetime_representation=DatetimeRepresentation.ISO8601,
4  strict_uuid=True)