Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/clarketm/pprintjson
A json pretty printer for Python 🐍
https://github.com/clarketm/pprintjson
json ppjson pprint pprintjson python
Last synced: 2 months ago
JSON representation
A json pretty printer for Python 🐍
- Host: GitHub
- URL: https://github.com/clarketm/pprintjson
- Owner: clarketm
- License: mit
- Created: 2018-09-07T22:00:17.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-16T23:00:38.000Z (about 2 years ago)
- Last Synced: 2024-10-08T14:06:06.207Z (4 months ago)
- Topics: json, ppjson, pprint, pprintjson, python
- Language: Python
- Homepage: https://pprintjson.readthedocs.io/en/latest/
- Size: 106 KB
- Stars: 15
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [pprintjson](https://pprintjson.readthedocs.io/en/latest/)
[![PyPi release](https://img.shields.io/pypi/v/pprintjson.svg)](https://pypi.org/project/pprintjson/)
[![PyPi versions](https://img.shields.io/pypi/pyversions/pprintjson.svg)](https://pypi.org/project/pprintjson/)
[![Downloads](https://pepy.tech/badge/pprintjson)](https://pepy.tech/project/pprintjson)
[![Documentation Status](https://readthedocs.org/projects/pprintjson/badge/?version=latest)](https://pprintjson.readthedocs.io/en/latest/?badge=latest)A json pretty printer for Python 🐍.
[Check out the pprintjson docs](https://pprintjson.readthedocs.io/en/latest/)
## Installation
Install with the standard [`json`](https://docs.python.org/3/library/json.html) JSON encoder
```bash
$ pip install pprintjson
```Install with the premier [`simplejson`](https://simplejson.readthedocs.io/en/latest/) JSON encoder
```bash
$ pip install pprintjson[simplejson]
```## Usage
```text
usage: pprintjson.py [-h] [-i num] [-o file] [-c cmd] [-v] [file]
A pretty-printing function for json.
positional arguments:
file json to pretty-printoptional arguments:
-h, --help show this help message and exit
-i num, --indent num indent number of spaces at each level (default: 4)
-o file, --output file write output to instead of stdout (default: stdout)
-c cmd, --command cmd json to pretty-print
-v, --version show program's version number and exit```
### Script
Pretty print JSON from a **file** using the `pprintjson` CLI.
```bash
$ pprintjson "./path/to/file.json"
```Pretty print JSON from a **stdin** using the `pprintjson` CLI.
```bash
$ echo '{ "a": 1, "b": "string", "c": true }' | pprintjson
```Pretty print JSON from a **string** using the `pprintjson` CLI.
```bash
$ pprintjson -c '{ "a": 1, "b": "string", "c": true }'
```Pretty print JSON from a **string** with an *indent* of **1**.
```bash
$ pprintjson -c '{ "a": 1, "b": "string", "c": true }' -i 1
```Pretty print JSON from a **string** and save *output* to a file **output.json**.
```bash
$ pprintjson -c '{ "a": 1, "b": "string", "c": true }' -o ./output.json
```### Module
Pretty print JSON from a **dict** using the `pprintjson` module.
```python
# 1. import the "pprintjson" function.
from pprintjson import pprintjson as ppjson# 2. pretty print JSON.
obj = { "a": 1, "b": "string", "c": True }ppjson(obj)
```![stdout](https://raw.githubusercontent.com/clarketm/pprintjson/master/pprintjson.png)
## License
MIT © [**Travis Clarke**](https://blog.travismclarke.com/)