diff --git a/cli/cmd/inspect.go b/cli/cmd/inspect.go index 20997d86..2e964799 100644 --- a/cli/cmd/inspect.go +++ b/cli/cmd/inspect.go @@ -56,7 +56,7 @@ func runInspect(ctx context.Context, id string) error { if err != nil { return err } - fmt.Println(j) + fmt.Print(j) return nil } diff --git a/formatter/formatter.go b/formatter/formatter.go index 6686319f..52cd9d0d 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -38,11 +38,11 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func s := reflect.ValueOf(toJSON) for i := 0; i < s.Len(); i++ { obj := s.Index(i).Interface() - jsonLine, err := ToCompressedJSON(obj) + jsonLine, err := ToJSON(obj, "", "") if err != nil { return err } - _, _ = fmt.Fprintln(outWriter, jsonLine) + _, _ = fmt.Fprint(outWriter, jsonLine) } default: outJSON, err := ToStandardJSON(toJSON) diff --git a/formatter/json.go b/formatter/json.go index a86e3f20..afadb0c8 100644 --- a/formatter/json.go +++ b/formatter/json.go @@ -17,6 +17,7 @@ package formatter import ( + "bytes" "encoding/json" ) @@ -24,18 +25,15 @@ const standardIndentation = " " // ToStandardJSON return a string with the JSON representation of the interface{} func ToStandardJSON(i interface{}) (string, error) { - b, err := json.MarshalIndent(i, "", standardIndentation) - if err != nil { - return "", err - } - return string(b), nil + return ToJSON(i, "", standardIndentation) } -// ToCompressedJSON return a string with the JSON representation of the interface{} -func ToCompressedJSON(i interface{}) (string, error) { - b, err := json.Marshal(i) - if err != nil { - return "", err - } - return string(b), nil +// ToJSON return a string with the JSON representation of the interface{} +func ToJSON(i interface{}, prefix string, indentation string) (string, error) { + buffer := &bytes.Buffer{} + encoder := json.NewEncoder(buffer) + encoder.SetEscapeHTML(false) + encoder.SetIndent(prefix, indentation) + err := encoder.Encode(i) + return buffer.String(), err }