Output JSON with spaces not tabs

This commit is contained in:
Seth Vargo 2017-08-28 16:45:04 -04:00
parent 7f6aa892a4
commit ac63ed573b
No known key found for this signature in database
GPG Key ID: C921994F9C27E0FF

View File

@ -1,7 +1,6 @@
package command package command
import ( import (
"bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -53,17 +52,15 @@ var Formatters = map[string]Formatter{
} }
// An output formatter for json output of an object // An output formatter for json output of an object
type JsonFormatter struct { type JsonFormatter struct{}
}
func (j JsonFormatter) Output(ui cli.Ui, secret *api.Secret, data interface{}) error { func (j JsonFormatter) Output(ui cli.Ui, secret *api.Secret, data interface{}) error {
b, err := json.Marshal(data) b, err := json.MarshalIndent(data, "", " ")
if err == nil { if err != nil {
var out bytes.Buffer return err
json.Indent(&out, b, "", "\t")
ui.Output(out.String())
} }
return err ui.Output(string(b))
return nil
} }
// An output formatter for yaml output format of an object // An output formatter for yaml output format of an object