prettify/main.go

28 lines
503 B
Go
Raw Normal View History

2020-05-10 13:36:48 +00:00
package prettify
import (
"encoding/json"
"fmt"
"github.com/TylerBrock/colorjson"
)
// PrettyPrint will beautify the output of
func PrettyPrint(body interface{}) {
b, err := json.Marshal(body)
var obj map[string]interface{}
//json.Unmarshal([]byte(body), &obj)
json.Unmarshal(b, &obj)
// Make a custom formatter with indent set
f := colorjson.NewFormatter()
f.Indent = 2
// Marshall the Colorized JSON
s, err := f.Marshal(obj)
if err != nil {
panic(err)
}
fmt.Println(string(s))
}