indent.go 345 Bytes
Newer Older
lukasburgey's avatar
lukasburgey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package indent

import (
	"bytes"
	"encoding/json"
)

var (
	prefix = ""
	indent = "  "
)

// Indent indents a json string if possible
// if unsuccessful it just returns src
func Indent(src []byte) (ds []byte) {
	buf := new(bytes.Buffer)
	err := json.Indent(buf, src, prefix, indent)
	if err != nil {
		return src
	}
	ds = buf.Bytes()
	return
}