Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TylerBrock/colorjson
Fast Color JSON Marshaller + Pretty Printer for Golang
https://github.com/TylerBrock/colorjson
color golang json marshaller no-dependencies pretty-print
Last synced: 30 days ago
JSON representation
Fast Color JSON Marshaller + Pretty Printer for Golang
- Host: GitHub
- URL: https://github.com/TylerBrock/colorjson
- Owner: TylerBrock
- License: mit
- Created: 2017-08-17T03:10:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-26T02:36:16.000Z (almost 2 years ago)
- Last Synced: 2024-11-07T07:23:43.579Z (about 1 month ago)
- Topics: color, golang, json, marshaller, no-dependencies, pretty-print
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 149
- Watchers: 3
- Forks: 26
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - ColorJSON - Print color JSON in terminal (Open source library / JSON)
README
ColorJSON: The Fast Color JSON Marshaller for Go
================================================
![ColorJSON Output](https://i.imgur.com/pLtCXhb.png)
What is this?
-------------This package is based heavily on hokaccha/go-prettyjson but has some noticible differences:
- Over twice as fast (recursive descent serialization uses buffer instead of string concatenation)
```
BenchmarkColorJSONMarshall-4 500000 2498 ns/op
BenchmarkPrettyJSON-4 200000 6145 ns/op
```
- more customizable (ability to have zero indent, print raw json strings, etc...)
- better defaults (less bold colors)ColorJSON was built in order to produce fast beautiful colorized JSON output for [Saw](http://github.com/TylerBrock/saw).
Installation
------------```sh
go get -u github.com/TylerBrock/colorjson
```Usage
-----Setup
```go
import "github.com/TylerBrock/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
```go
s, _ := colorjson.Marshal(obj)
fmt.Println(string(s))
```Customization (Custom Indent)
```go
f := colorjson.NewFormatter()
f.Indent = 2s, _ := f.Marshal(v)
fmt.Println(string(s))
```