28 lines
503 B
Go
28 lines
503 B
Go
|
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))
|
||
|
}
|