Skip to content
Node: JSON.parse/stringifygithub.com/sahilkhaire/gox/json

Pretty

Overview ​

Pretty returns indented JSON.

Part of the json package — Node.js analog: JSON.parse/stringify.

Signature ​

go
func Pretty(v any) (string, error)

Compare: Node.js · Standard Go · gox ​

js
JSON.stringify(obj, null, 2);
go
b, err := json.MarshalIndent(obj, "", "  ")
go
import "github.com/sahilkhaire/gox/json"

s, err := goxjson.Pretty(map[string]int{"a": 1})

Example ​

go
import "github.com/sahilkhaire/gox/json"

s, err := goxjson.Pretty(map[string]int{"a": 1})

Tips ​

Import github.com/sahilkhaire/gox/json and call Pretty directly. See the comparison below for the standard library equivalent.

Standard library alternative ​

Use the standard library directly:

go
b, err := json.MarshalIndent(obj, "", "  ")

← Back to json package overview

MIT Licensed · Built for Node.js developers moving to Go