Skip to content

Commit

Permalink
Merge pull request #953 from dwillist/952_inspect_builder_json_format
Browse files Browse the repository at this point in the history
Format inspect-builder json output before printing
  • Loading branch information
dfreilich authored Dec 3, 2020
2 parents 12ad921 + 15f0f8c commit 709c41b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/builder/writer/json.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package writer

import (
"bytes"
"encoding/json"
)

Expand All @@ -11,7 +12,15 @@ type JSON struct {
func NewJSON() BuilderWriter {
return &JSON{
StructuredFormat: StructuredFormat{
MarshalFunc: json.Marshal,
MarshalFunc: func(i interface{}) ([]byte, error) {
buf, err := json.Marshal(i)
if err != nil {
return []byte{}, err
}
formattedBuf := bytes.NewBuffer(nil)
err = json.Indent(formattedBuf, buf, "", " ")
return formattedBuf.Bytes(), err
},
},
}
}

0 comments on commit 709c41b

Please sign in to comment.