| 240 | |
| 241 | |
| 242 | class JSONOptions(_BASE_CLASS): |
| 243 | json_mode: int |
| 244 | strict_number_long: bool |
| 245 | datetime_representation: int |
| 246 | strict_uuid: bool |
| 247 | document_class: Type[MutableMapping[str, Any]] |
| 248 | |
| 249 | def __init__(self, *args: Any, **kwargs: Any): |
| 250 | """Encapsulates JSON options for :func:`dumps` and :func:`loads`. |
| 251 | |
| 252 | :param strict_number_long: If ``True``, :class:`~bson.int64.Int64` objects |
| 253 | are encoded to MongoDB Extended JSON's *Strict mode* type |
| 254 | `NumberLong`, ie ``'{"$numberLong": "<number>" }'``. Otherwise they |
| 255 | will be encoded as an `int`. Defaults to ``False``. |
| 256 | :param datetime_representation: The representation to use when encoding |
| 257 | instances of :class:`datetime.datetime`. Defaults to |
| 258 | :const:`~DatetimeRepresentation.LEGACY`. |
| 259 | :param strict_uuid: If ``True``, :class:`uuid.UUID` object are encoded to |
| 260 | MongoDB Extended JSON's *Strict mode* type `Binary`. Otherwise it |
| 261 | will be encoded as ``'{"$uuid": "<hex>" }'``. Defaults to ``False``. |
| 262 | :param json_mode: The :class:`JSONMode` to use when encoding BSON types to |
| 263 | Extended JSON. Defaults to :const:`~JSONMode.LEGACY`. |
| 264 | :param document_class: BSON documents returned by :func:`loads` will be |
| 265 | decoded to an instance of this class. Must be a subclass of |
| 266 | :class:`collections.MutableMapping`. Defaults to :class:`dict`. |
| 267 | :param uuid_representation: The :class:`~bson.binary.UuidRepresentation` |
| 268 | to use when encoding and decoding instances of :class:`uuid.UUID`. |
| 269 | Defaults to :const:`~bson.binary.UuidRepresentation.UNSPECIFIED`. |
| 270 | :param tz_aware: If ``True``, MongoDB Extended JSON's *Strict mode* type |
| 271 | `Date` will be decoded to timezone aware instances of |
| 272 | :class:`datetime.datetime`. Otherwise they will be naive. Defaults |
| 273 | to ``False``. |
| 274 | :param tzinfo: A :class:`datetime.tzinfo` subclass that specifies the |
| 275 | timezone from which :class:`~datetime.datetime` objects should be |
| 276 | decoded. Defaults to :const:`~bson.tz_util.utc`. |
| 277 | :param datetime_conversion: Specifies how UTC datetimes should be decoded |
| 278 | within BSON. Valid options include 'datetime_ms' to return as a |
| 279 | DatetimeMS, 'datetime' to return as a datetime.datetime and |
| 280 | raising a ValueError for out-of-range values, 'datetime_auto' to |
| 281 | return DatetimeMS objects when the underlying datetime is |
| 282 | out-of-range and 'datetime_clamp' to clamp to the minimum and |
| 283 | maximum possible datetimes. Defaults to 'datetime'. See |
| 284 | `handling out of range datetimes <https://www.mongodb.com/docs/languages/python/pymongo-driver/current/data-formats/dates-and-times/#handling-out-of-range-datetimes>`_ for details. |
| 285 | :param args: arguments to :class:`~bson.codec_options.CodecOptions` |
| 286 | :param kwargs: arguments to :class:`~bson.codec_options.CodecOptions` |
| 287 | |
| 288 | .. seealso:: The specification for Relaxed and Canonical `Extended JSON`_. |
| 289 | |
| 290 | .. versionchanged:: 4.0 |
| 291 | The default for `json_mode` was changed from :const:`JSONMode.LEGACY` |
| 292 | to :const:`JSONMode.RELAXED`. |
| 293 | The default for `uuid_representation` was changed from |
| 294 | :const:`~bson.binary.UuidRepresentation.PYTHON_LEGACY` to |
| 295 | :const:`~bson.binary.UuidRepresentation.UNSPECIFIED`. |
| 296 | |
| 297 | .. versionchanged:: 3.5 |
| 298 | Accepts the optional parameter `json_mode`. |
| 299 |
no outgoing calls