...
1ColorJSON: The Fast Color JSON Marshaller for Go
2================================================
3![ColorJSON Output](https://i.imgur.com/pLtCXhb.png)
4What is this?
5-------------
6
7This package is based heavily on hokaccha/go-prettyjson but has some noticible differences:
8 - Over twice as fast (recursive descent serialization uses buffer instead of string concatenation)
9 ```
10 BenchmarkColorJSONMarshall-4 500000 2498 ns/op
11 BenchmarkPrettyJSON-4 200000 6145 ns/op
12 ```
13 - more customizable (ability to have zero indent, print raw json strings, etc...)
14 - better defaults (less bold colors)
15
16ColorJSON was built in order to produce fast beautiful colorized JSON output for [Saw](http://github.com/TylerBrock/saw).
17
18Installation
19------------
20
21```sh
22go get -u github.com/TylerBrock/colorjson
23```
24
25Usage
26-----
27
28Setup
29
30```go
31import "github.com/TylerBrock/colorjson"
32
33str := `{
34 "str": "foo",
35 "num": 100,
36 "bool": false,
37 "null": null,
38 "array": ["foo", "bar", "baz"],
39 "obj": { "a": 1, "b": 2 }
40}`
41
42// Create an intersting JSON object to marshal in a pretty format
43var obj map[string]interface{}
44json.Unmarshal([]byte(str), &obj)
45```
46
47Vanilla Usage
48
49```go
50s, _ := colorjson.Marshal(obj)
51fmt.Println(string(s))
52```
53
54Customization (Custom Indent)
55```go
56f := colorjson.NewFormatter()
57f.Indent = 2
58
59s, _ := f.Marshal(v)
60fmt.Println(string(s))
61```
View as plain text