← Runnable Projects

阅读中文版本

Python JSON Pretty-Print CLI

Python JSON Pretty-Print — a runnable python project with source, install and run commands, and expected output.

intermediatepythonunverified

Project

py-json-pretty-cli

Entry point: jp.py

Install

python jp.py data.json

Run

python jp.py sample.json

Test

pytest jp_test.py

Expected output

Loads JSON and re-emits with indent=2 and sorted keys.

Dependencies

  • python >=3.10

Verification evidence

Source reviewed against python standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Python JSON Pretty-Print CLI is a self-contained python command-line program. Loads JSON and re-emits with indent=2 and sorted keys.

Install and run

python jp.py data.json
python jp.py sample.json

Project structure

py-json-pretty-cli/
├── jp.py
└── README snippet above

Key source

# jp.py
import json, sys
with open(sys.argv[1]) as f:
    print(json.dumps(json.load(f), indent=2, sort_keys=True))

Testing

pytest jp_test.py

Expected output

When run with the documented command, the program prints:

{\n  "a": 1,\n  "b": 2\n}

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.