@@ -45,28 +45,28 @@ Customizing JSON Encoding
4545-------------------------
4646
4747If you're using Eliot's JSON output you may wish to customize encoding.
48- By default Eliot uses ``eliot.json.EliotJSONEncoder `` (a subclass of `` json.JSONEncoder ``) to encode objects .
49- You can customize encoding by passing a custom subclass to either ``eliot.FileDestination `` or ``eliot.to_file ``:
48+ By default Eliot uses ``eliot.json.json_default `` to encode objects that the default JSON serializer doesn't handle .
49+ You can customize encoding by passing a custom function to either ``eliot.FileDestination `` or ``eliot.to_file ``:
5050
5151.. code-block :: python
5252
53- from eliot.json import EliotJSONEncoder
53+ from eliot.json import json_default
5454 from eliot import to_file
5555
5656
5757 class MyClass :
5858 def __init__ (self , x ):
5959 self .x = x
6060
61- class MyEncoder (EliotJSONEncoder ):
62- def default (self , obj ):
63- if isinstance (obj, MyClass):
64- return {" x" : obj.x}
65- return EliotJSONEncoder.default(self , obj)
61+ def default (self , obj ):
62+ if isinstance (obj, MyClass):
63+ return {" x" : obj.x}
64+ return json_default(obj)
6665
67- to_file(open (" eliot.log" , " ab" ), encoder = MyEncoder)
66+ to_file(open (" eliot.log" , " ab" ), default = default)
6867
6968 For more details on JSON encoding see the Python `JSON documentation <https://docs.python.org/3/library/json.html >`_.
69+ Note that Eliot uses `orjson <https://pypi.org/project/orjson/ >`_ on CPython (for performance), and the built-in JSON module on PyPy.
7070
7171.. _add_global_fields :
7272
0 commit comments