Simple command-line tool to pretty-print JSON using rich.
JTOOL reads JSON from a file, from standard input (pipe), or directly from a command-line argument and pretty-prints it to the terminal using the rich library.
- Python 3.8+ installed
uvinstalled and configured for this project (used to create/activate the virtualenv and install dependencies)- If you don't have
uv, install it according to your environment's instructions.
- If you don't have
Clone the repo and use uv to synchronise dependencies and create the virtual environment:
git clone https://github.com/mosesborore/jtool.git
cd jtool
# create venv and install dependencies using uv
uv syncuv sync will create/refresh the virtual environment and install the project's dependencies (for example rich). After this you're ready to run the tool via uv run (which runs commands inside the project's virtual environment).
You can run JTOOL using uv run so dependencies from the project's environment are used.
- Pretty-print JSON from a file
uv run python3 main.py ./path/to/file.json
# or, after adding an alias (see below)
jtool ./path/to/file.json- Pretty-print JSON piped from stdin (useful for
curl/cat/ command pipelines)
echo '{"test": "json"}' | uv run python3 main.py
# or
cat file.json | uv run python3 main.py
# or
curl -s https://api.example.com/data | uv run python3 main.pyExample output:
{
"test": "json"
}- Pretty-print when providing a JSON string directly as an argument
uv run python3 main.py --data '{"test": "json"}'
# or after aliasing
jtool --data '{"test": "json"}'- Show help
uv run python3 main.py --helpNotes:
- If the JSON is invalid the tool will report a parse error.
- For large JSON outputs, your terminal will be able to scroll as usual.
Add an alias to your shell configuration (e.g., ~/.bashrc or ~/.zshrc) so you can run jtool from anywhere and still leverage uv to run inside the project environment.
Simple alias that ensures commands are executed inside the uv environment:
# Edit ~/.bashrc or ~/.zshrc and add:
alias jtool="uv run python3 /path/to/jtool/main.py"
# Then reload your shell config:
source ~/.bashrc # or `source ~/.zshrc`
# Try it:
jtool --helpAlternative (preferred if you want a simpler alias without calling uv run each time):
- Make
main.pyexecutable, add a shebang at the top (#!/usr/bin/env python3) and, if you want to ensure the environment is the project's venv, create a small wrapper script that callsuv run(and place that wrapper in a directory on yourPATH).
Example wrapper (place it in ~/bin/jtool and make it executable):
#!/usr/bin/env bash
# wrapper that runs the script inside the project's uv environment
uv run python3 /path/to/jtool/main.py "$@"- From a file:
jtool ./examples/sample.json
# (or directly)
uv run python3 main.py ./examples/sample.json- From a pipe:
curl -s https://api.example.com/data | jtool
# (or directly)
curl -s https://api.example.com/data | uv run python3 main.py- From inline JSON:
jtool --data '{"name": "Alice", "age": 30}'
# (or directly)
uv run python3 main.py --data '{"name": "Alice", "age": 30}'