← Runnable Projects

阅读中文版本

Go JSON Pretty-Print CLI

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

intermediategounverified

Project

go-json-pretty-cli

Entry point: main.go

Install

go run main.go data.json

Run

go run main.go sample.json

Test

go test

Expected output

Reads JSON, re-indents with two spaces, and prints it.

Dependencies

  • go >=1.22

Verification evidence

Source reviewed against go 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

Go JSON Pretty-Print CLI is a self-contained go command-line program. Reads JSON, re-indents with two spaces, and prints it.

Install and run

go run main.go data.json
go run main.go sample.json

Project structure

go-json-pretty-cli/
├── main.go
└── README snippet above

Key source

// main.go
package main
import ("encoding/json"; "fmt"; "os")
func main() {
    b, _ := os.ReadFile(os.Args[1]); var v any
    json.Unmarshal(b, &v); out, _ := json.MarshalIndent(v, "", "  ")
    fmt.Println(string(out))
}

Testing

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