Rust JSON Pretty-Print CLI
Rust JSON Pretty-Print — a runnable rust project with source, install and run commands, and expected output.
Project
rust-json-pretty-cli
Entry point: main.rs
Install
cargo run -- data.jsonRun
cargo run -- sample.jsonTest
cargo testExpected output
Reads JSON, re-indents with two spaces, and prints it.Dependencies
- rust >=1.75
- serde_json 1.0
Verification evidence
Source reviewed against rust 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
Rust JSON Pretty-Print CLI is a self-contained rust command-line program. Reads JSON, re-indents with two spaces, and prints it.
Install and run
cargo run -- data.json
cargo run -- sample.json
Project structure
rust-json-pretty-cli/
├── main.rs
└── README snippet above
Key source
// main.rs
use serde_json::{Value, from_str, to_string_pretty}; use std::fs;
fn main() {
let s = fs::read_to_string(std::env::args().nth(1).unwrap()).unwrap();
let v: Value = from_str(&s).unwrap();
println!("{}", to_string_pretty(&v).unwrap());
}
Testing
cargo test
Expected output
When run with the documented command, the program prints:
{\n "a": 1\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.