@@ -151,14 +151,16 @@ def dumps(
151151` dumps() ` serializes Python objects to JSON.
152152
153153It natively serializes
154- ` str ` , ` dict ` , ` list ` , ` tuple ` , ` int ` , ` float ` , ` bool ` , ` None ` ,
154+ ` str ` , ` dict ` , ` frozendict ` , ` list ` , ` tuple ` , ` int ` , ` float ` , ` bool ` , ` None ` ,
155155` dataclasses.dataclass ` , ` typing.TypedDict ` , ` datetime.datetime ` ,
156156` datetime.date ` , ` datetime.time ` , ` uuid.UUID ` , ` numpy.ndarray ` , and
157157` orjson.Fragment ` instances. It supports arbitrary types through ` default ` . It
158158serializes subclasses of ` str ` , ` int ` , ` dict ` , ` list ` ,
159159` dataclasses.dataclass ` , and ` enum.Enum ` . It does not serialize subclasses
160- of ` tuple ` to avoid serializing ` namedtuple ` objects as arrays. To avoid
161- serializing subclasses, specify the option ` orjson.OPT_PASSTHROUGH_SUBCLASS ` .
160+ of ` tuple ` to avoid serializing ` namedtuple ` objects as arrays. It does not
161+ serialize subclasses of ` float ` or ` frozendict ` due to implementation details
162+ in CPython. To avoid serializing subclasses, specify the
163+ option ` orjson.OPT_PASSTHROUGH_SUBCLASS ` .
162164
163165The output is a ` bytes ` object containing UTF-8.
164166
@@ -174,8 +176,8 @@ It raises `JSONEncodeError` on a `str` that contains invalid UTF-8.
174176It raises ` JSONEncodeError ` on an integer that exceeds 64 bits by default or,
175177with ` OPT_STRICT_INTEGER ` , 53 bits.
176178
177- It raises ` JSONEncodeError ` if a ` dict ` has a key of a type other than ` str ` ,
178- unless ` OPT_NON_STR_KEYS ` is specified.
179+ It raises ` JSONEncodeError ` if a ` dict ` or ` frozendict ` has a key of a type
180+ other than ` str ` , unless ` OPT_NON_STR_KEYS ` is specified.
179181
180182It raises ` JSONEncodeError ` if the output of ` default ` recurses to handling by
181183` default ` more than 254 levels deep.
@@ -326,9 +328,10 @@ b'"1970-01-01T00:00:00+00:00"'
326328
327329##### OPT_NON_STR_KEYS
328330
329- Serialize ` dict ` keys of type other than ` str ` . This allows ` dict ` keys
330- to be one of ` str ` , ` int ` , ` float ` , ` bool ` , ` None ` , ` datetime.datetime ` ,
331- ` datetime.date ` , ` datetime.time ` , ` enum.Enum ` , and ` uuid.UUID ` . For comparison,
331+ Serialize ` dict ` and ` frozendict ` keys of type other than ` str ` . This allows
332+ ` dict ` and ` frozendict ` keys to be one of ` str ` , ` int ` , ` float ` ,
333+ ` bool ` , ` None ` , ` datetime.datetime ` , ` datetime.date ` ,
334+ ` datetime.time ` , ` enum.Enum ` , and ` uuid.UUID ` . For comparison,
332335the standard library serializes ` str ` , ` int ` , ` float ` , ` bool ` or ` None ` by
333336default. orjson benchmarks as being faster at serializing non-` str ` keys
334337than other libraries. This option is slower for ` str ` keys than the default.
@@ -462,7 +465,7 @@ TypeError: Type is not JSON serializable: datetime.datetime
462465b ' {"created_at":"Thu, 01 Jan 1970 00:00:00 GMT"}'
463466```
464467
465- This does not affect datetimes in ` dict ` keys if using OPT_NON_STR_KEYS.
468+ This does not affect datetimes in ` dict ` or ` frozendict ` keys if using ` OPT_NON_STR_KEYS ` .
466469
467470##### OPT_PASSTHROUGH_SUBCLASS
468471
@@ -487,8 +490,8 @@ TypeError: Type is not JSON serializable: Secret
487490b ' "******"'
488491```
489492
490- This does not affect serializing subclasses as ` dict ` keys if using
491- OPT_NON_STR_KEYS.
493+ This does not affect serializing subclasses as ` dict ` or ` frozendict ` keys
494+ if using ` OPT_NON_STR_KEYS ` .
492495
493496##### OPT_SERIALIZE_DATACLASS
494497
@@ -509,9 +512,9 @@ required to serialize `uuid.UUID` instances. For more, see
509512
510513##### OPT_SORT_KEYS
511514
512- Serialize ` dict ` keys in sorted order. The default is to serialize in an
513- unspecified order. This is equivalent to ` sort_keys=True ` in the standard
514- library.
515+ Serialize ` dict ` and ` frozendict ` keys in sorted order. The default is
516+ to serialize in an unspecified order. This is equivalent
517+ to ` sort_keys=True ` in the standard library.
515518
516519This can be used to ensure the order is deterministic for hashing or tests.
517520It has a substantial performance penalty and is not recommended in general.
0 commit comments