github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/inspectimage/writer/json.go (about) 1 package writer 2 3 import ( 4 "bytes" 5 "encoding/json" 6 ) 7 8 type JSON struct { 9 StructuredFormat 10 } 11 12 func NewJSON() *JSON { 13 return &JSON{ 14 StructuredFormat: StructuredFormat{ 15 MarshalFunc: func(i interface{}) ([]byte, error) { 16 buf := bytes.NewBuffer(nil) 17 if err := json.NewEncoder(buf).Encode(i); err != nil { 18 return []byte{}, err 19 } 20 21 formattedBuf := bytes.NewBuffer(nil) 22 if err := json.Indent(formattedBuf, buf.Bytes(), "", " "); err != nil { 23 return []byte{}, err 24 } 25 return formattedBuf.Bytes(), nil 26 }, 27 }, 28 } 29 }