mirror of
https://github.com/therootcompany/golib.git
synced 2025-10-07 01:28:19 +00:00
31 lines
518 B
Go
31 lines
518 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/therootcompany/golib/colorjson"
|
|
)
|
|
|
|
func main() {
|
|
str := `{
|
|
"str": "foo",
|
|
"num": 100,
|
|
"bool": false,
|
|
"null": null,
|
|
"array": ["foo", "bar", "baz"],
|
|
"obj": { "a": 1, "b": 2 }
|
|
}`
|
|
|
|
var obj map[string]interface{}
|
|
json.Unmarshal([]byte(str), &obj)
|
|
|
|
// Make a custom formatter with indent set
|
|
f := colorjson.NewFormatter()
|
|
f.Indent = 4
|
|
|
|
// Marshall the Colorized JSON
|
|
s, _ := f.Marshal(obj)
|
|
fmt.Println(string(s))
|
|
}
|