prettify/main.go
2020-05-10 16:03:39 +02:00

28 lines
496 B
Go

package prettify
import (
"encoding/json"
"fmt"
"github.com/TylerBrock/colorjson"
)
// Print will beautify the output of body
func Print(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))
}