| 123456789101112131415161718192021 |
- package main
- import (
- "encoding/json"
- "fmt"
- "io"
- )
- // encodeJSON writes v as two-space indented JSON followed by a newline.
- // Every JSON-emitting command goes through here so their output shape stays
- // identical — consumers should not have to special-case one command.
- func encodeJSON(w io.Writer, v any) error {
- data, err := json.MarshalIndent(v, "", " ")
- if err != nil {
- return fmt.Errorf("encode json: %w", err)
- }
- if _, err := fmt.Fprintln(w, string(data)); err != nil {
- return err
- }
- return nil
- }
|