Skip to content

Commit

Permalink
Update JSONRenderer docs (#535)
Browse files Browse the repository at this point in the history
I noticed *json_kw* was referred to in docs but the the actual parameter is called *dumps_kw*. While fixing that I also wanted to add a little bit of info I had to figure out on my own, which was that if you want `orjson` to handle serialization of dataclasses, datetimes, etc. natively, you need to pass a `default` (I used the `singledispatch` to use `str` by default and handle Pydantic objects and sets to work better with our logging systems)
  • Loading branch information
jerr0328 authored Aug 1, 2023
1 parent 5338886 commit 334125e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ API Reference

Please note that additionally to strings, you can also return any type the standard library JSON module knows about -- like in this example a list.

If you choose to pass a *default* parameter as part of *json_kw*, support for ``__structlog__`` is disabled.
If you choose to pass a *default* parameter as part of *dumps_kw*, support for ``__structlog__`` is disabled.
This can be useful when used together with more elegant serialization methods like :func:`functools.singledispatch`: `Better Python Object Serialization <https://hynek.me/articles/serialization/>`_.
Using a `default` to disable the ``__structlog__`` serialization is also useful if you are using ``orjson`` and want to rely on it to serialize ``datetime`` and other objects natively.

.. tip::

Expand Down

0 comments on commit 334125e

Please sign in to comment.