# How to log data as JSON with Python

If you are new to logging in Python, please feel free to start with our [Introduction to Python logging](https://betterstack.com/community/guides/logging/how-to-start-logging-with-python/) to get started smoothly. Otherwise, here is how to log data as JSON in Python:

### The simplest way is to use a custom module:

```bash
pip install json-logging
```

To initialize the logger when not using the web framework, use this line of
code:

```python
json_logging.init_non_web(enable_json=True)
```

For web applications, replace `_non_web` with the name of framework.
(`_flask, _sanic,...`)

More documentation about this module
is [provided here](https://github.com/bobbui/json-logging-python). If you would like to have more options when it comes to logging your apps, have a look at our [Guide to logging with Loguru](https://betterstack.com/community/guides/logging/loguru/), which is the most popular third-party logging framework for Python.
