package main import ( "bytes" "encoding/json" "fmt" "io" "os" ) // pretty formats exactly one JSON value using two-space indentation. func pretty(src []byte) ([]byte, error) { src = bytes.TrimSpace(src) if len(src) == 0 { return nil, fmt.Errorf("empty input") } var out bytes.Buffer if err := json.Indent(&out, src, "", " "); err != nil { return nil, err } out.WriteByte('\n') return out.Bytes(), nil } func main() { src, err := io.ReadAll(os.Stdin) if err != nil { fmt.Fprintln(os.Stderr, "read:", err) os.Exit(1) } out, err := pretty(src) if err != nil { fmt.Fprintln(os.Stderr, "invalid JSON:", err) os.Exit(1) } if _, err := os.Stdout.Write(out); err != nil { fmt.Fprintln(os.Stderr, "write:", err) os.Exit(1) } } // Example tests: // // Input: {"name":"Ada","active":true} // Output: // { // "name": "Ada", // "active": true // } // // Input: [1,{"x":null}] // Output: // [ // 1, // { // "x": null // } // ]