OpenQuizz
Une application de gestion des contenus pédagogiques
JSONOptions Class Reference
Inheritance diagram for JSONOptions:
Collaboration diagram for JSONOptions:

Public Member Functions

def __new__ (cls, strict_number_long=False, datetime_representation=DatetimeRepresentation.LEGACY, strict_uuid=False, json_mode=JSONMode.LEGACY, *args, **kwargs)
 
def with_options (self, **kwargs)
 
- Public Member Functions inherited from CodecOptions
def __new__ (cls, document_class=dict, tz_aware=False, uuid_representation=None, unicode_decode_error_handler="strict", tzinfo=None, type_registry=None)
 
def __repr__ (self)
 

Data Fields

 json_mode
 
 strict_number_long
 
 datetime_representation
 
 strict_uuid
 

Detailed Description

Encapsulates JSON options for :func:`dumps` and :func:`loads`.

:Parameters:
  - `strict_number_long`: If ``True``, :class:`~bson.int64.Int64` objects
    are encoded to MongoDB Extended JSON's *Strict mode* type
    `NumberLong`, ie ``'{"$numberLong": "<number>" }'``. Otherwise they
    will be encoded as an `int`. Defaults to ``False``.
  - `datetime_representation`: The representation to use when encoding
    instances of :class:`datetime.datetime`. Defaults to
    :const:`~DatetimeRepresentation.LEGACY`.
  - `strict_uuid`: If ``True``, :class:`uuid.UUID` object are encoded to
    MongoDB Extended JSON's *Strict mode* type `Binary`. Otherwise it
    will be encoded as ``'{"$uuid": "<hex>" }'``. Defaults to ``False``.
  - `json_mode`: The :class:`JSONMode` to use when encoding BSON types to
    Extended JSON. Defaults to :const:`~JSONMode.LEGACY`.
  - `document_class`: BSON documents returned by :func:`loads` will be
    decoded to an instance of this class. Must be a subclass of
    :class:`collections.MutableMapping`. Defaults to :class:`dict`.
  - `uuid_representation`: The :class:`~bson.binary.UuidRepresentation`
    to use when encoding and decoding instances of :class:`uuid.UUID`.
    Defaults to :const:`~bson.binary.UuidRepresentation.PYTHON_LEGACY`.
  - `tz_aware`: If ``True``, MongoDB Extended JSON's *Strict mode* type
    `Date` will be decoded to timezone aware instances of
    :class:`datetime.datetime`. Otherwise they will be naive. Defaults
    to ``True``.
  - `tzinfo`: A :class:`datetime.tzinfo` subclass that specifies the
    timezone from which :class:`~datetime.datetime` objects should be
    decoded. Defaults to :const:`~bson.tz_util.utc`.
  - `args`: arguments to :class:`~bson.codec_options.CodecOptions`
  - `kwargs`: arguments to :class:`~bson.codec_options.CodecOptions`

.. seealso:: The specification for Relaxed and Canonical `Extended JSON`_.

.. versionadded:: 3.4

.. versionchanged:: 3.5
   Accepts the optional parameter `json_mode`.

Member Function Documentation

◆ __new__()

def __new__ (   cls,
  strict_number_long = False,
  datetime_representation = DatetimeRepresentation.LEGACY,
  strict_uuid = False,
  json_mode = JSONMode.LEGACY,
args,
**  kwargs 
)

◆ with_options()

def with_options (   self,
**  kwargs 
)
Make a copy of this JSONOptions, overriding some options::

    >>> from bson.json_util import CANONICAL_JSON_OPTIONS
    >>> CANONICAL_JSON_OPTIONS.tz_aware
    True
    >>> json_options = CANONICAL_JSON_OPTIONS.with_options(tz_aware=False)
    >>> json_options.tz_aware
    False

.. versionadded:: 3.12

Reimplemented from CodecOptions.

Field Documentation

◆ datetime_representation

datetime_representation

◆ json_mode

json_mode

◆ strict_number_long

strict_number_long

◆ strict_uuid

strict_uuid

The documentation for this class was generated from the following file: