diff --git a/main.go b/main.go index 2726c4e..2ffb666 100644 --- a/main.go +++ b/main.go @@ -10,15 +10,17 @@ import ( // Print will beautify the output of body func Print(body interface{}) { b, err := json.Marshal(body) + if err != nil { + panic(err) + } 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 + // Marshal the Colorized JSON s, err := f.Marshal(obj) if err != nil { panic(err) @@ -29,8 +31,26 @@ func Print(body interface{}) { } // PrintArray will beautify the output of an interface array (bodyArray) -func PrintArray(bodyArray []interface{}) { - for i := range bodyArray { - Print(bodyArray[i]) +func PrintArray(bodyArray interface{}) { + b, err := json.Marshal(bodyArray) + if err != nil { + panic(err) } + var obj []map[string]interface{} + json.Unmarshal(b, &obj) + + // Make a custom formatter with indent set + f := colorjson.NewFormatter() + f.Indent = 2 + + for i := range obj { + // Marshal the Colorized JSON + s, err := f.Marshal(obj[i]) + if err != nil { + panic(err) + } + // Print out string to stdout + fmt.Println(string(s)) + } + }