Install & Compatibility
Where this runs
tested against v4.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.090s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.076s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
JsonFormatter
✓ from pythonjsonlogger.jsonlogger import JsonFormatter
Make sure to use the full path for compatibility.
Basic usage of JsonFormatter to log messages in JSON format.
import logging
from pythonjsonlogger.jsonlogger import JsonFormatter
logger = logging.getLogger('my_logger')
handler = logging.StreamHandler()
formatter = JsonFormatter()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.info('This is a log message with JSON formatting')
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'json_log_formatter'
The `python-json-logger` package, which provides the `json_log_formatter` module, is not installed in the current Python environment.
fixpip install python-json-logger
ModuleNotFoundError: No module named 'python_json_logger'
Although the package is named `python-json-logger`, the main module containing the `JsonFormatter` class is `json_log_formatter`.
fixfrom json_log_formatter import JsonFormatter
ImportError: cannot import name 'JsonLogger' from 'json_log_formatter'
The class name `JsonLogger` is incorrect; the correct class for JSON formatting in this library is `JsonFormatter`.
fixfrom json_log_formatter import JsonFormatter
TypeError: Object of type <ClassName> is not JSON serializable
A log record contains an object (e.g., datetime, custom class instance) that the default JSON encoder cannot serialize, and no custom `json_default` function or `json_encoder` class was provided to `JsonFormatter`.
fixConfigure `JsonFormatter` with a `json_default` function to convert non-serializable objects into a serializable format:
```python
import datetime
from json_log_formatter import JsonFormatter
def custom_serializer(o):
if isinstance(o, datetime.datetime):
return o.isoformat()
raise TypeError(f"Object of type {o.__class__.__name__} is not JSON serializable")
formatter = JsonFormatter(json_default=custom_serializer)
``` TypeError: JsonFormatter.__init__() got an unexpected keyword argument 'some_arg'
An unrecognized or misspelled keyword argument was passed to the `JsonFormatter` constructor.
fixRefer to the library's documentation for the correct list of supported arguments for `JsonFormatter`, such as `json_default`, `json_encoder`, `json_message_key`, `json_extra`, etc.
Upgrade
Version history
4.2.0latest on PyPI · released Aug 15, 2026
Audit
Dependencies
No dependency data recorded yet.