This package is based heavily on TylerBrock/colorjson but uses direct-to-stream serialisation to a io.Writer
interface via an internal buffer.
go get -u github.com/relvacode/colorjson
Setup
import "github.com/relvacode/colorjson"
str := `{
"str": "foo",
"num": 100,
"bool": false,
"null": null,
"array": ["foo", "bar", "baz"],
"obj": { "a": 1, "b": 2 }
}`
// Create an intersting JSON object to marshal in a pretty format
var obj map[string]interface{}
json.Unmarshal([]byte(str), &obj)
Vanilla Usage
// Use stdout, or any other standard io.Writer interface
_, err := colorjson.Marshal(os.Stdout, obj)
Customization (Custom Indent)
f := colorjson.NewFormatter()
f.Indent = 2
_, err := f.Marshal(os.Stdout, obj)