Skip to content

Simple commandline tool to Pretty-print JSON using rich

License

Notifications You must be signed in to change notification settings

mosesborore/jtool

Repository files navigation

JTOOL

Simple command-line tool to pretty-print JSON using rich.

Quick summary

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.

Prerequisites

  • Python 3.8+ installed
  • uv installed 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.

Installation / setup

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 sync

uv 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).

Running the tool

You can run JTOOL using uv run so dependencies from the project's environment are used.

  1. 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
  1. 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.py

Example output:

{
  "test": "json"
}
  1. 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"}'
  1. Show help
uv run python3 main.py --help

Notes:

  • 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.

Making a convenient alias

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 --help

Alternative (preferred if you want a simpler alias without calling uv run each time):

  • Make main.py executable, 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 calls uv run (and place that wrapper in a directory on your PATH).

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 "$@"

Examples

  • 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}'

Screenshots

  • JSON from a file

    Pretty-print JSON from a file

  • JSON from direct arguments

    Pretty-print JSON from direct arguments

  • Piped data / standard input

    Pretty-print JSON from piped data

About

Simple commandline tool to Pretty-print JSON using rich

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages