Registry / observability / python-json-logger

python-json-logger

JSON →
library4.2.0pypypi✓ verified 27d ago

A JSON log formatter for the Python logging package that supports various JSON encoders. Current version is 4.0.0, with regular releases typically made every few months.

pip install python-json-logger
INSTALL
IMPORT
SIG · PYTHON-JSON-LOGGER
P
python-json-logger
observabilitypythonv4.2.0
Install
1.7s avg
Import
83ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.090s · 17.9MB
glibc
py 3.103.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')
Debug
Known issues
breakingThe use of some older imports has changed, e.g., 'from pythonjsonlogger.jsonlogger import jsonlogger' is incorrect.
fix
Migrate to 'from pythonjsonlogger.jsonlogger import JsonFormatter'.
affects: <4.0.0
gotchaEnsure that required fields are correctly specified in comma-separated format to avoid formatting issues.
fix
Use the new formatter syntax that supports comma-separated lists.
affects: >=4.0.0
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.
fix
pip 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`.
fix
from 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`.
fix
from 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`.
fix
Configure `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.
fix
Refer 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.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
2
Resources
python-json-logger — pip install python-json-logger · libregistry