30 lines
528 B
Go
30 lines
528 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)
|
|
}
|
|
|
|
// Print out string to stdout
|
|
fmt.Println(string(s))
|
|
}
|