diff --git a/go/oasis-node/cmd/common/json.go b/go/oasis-node/cmd/common/json.go new file mode 100644 index 00000000000..1a07ad97996 --- /dev/null +++ b/go/oasis-node/cmd/common/json.go @@ -0,0 +1,15 @@ +package common + +import ( + "encoding/json" + "fmt" +) + +// PrettyJSONMarshal returns pretty-printed JSON encoding of v. +func PrettyJSONMarshal(v interface{}) ([]byte, error) { + formatted, err := json.MarshalIndent(v, "", " ") + if err != nil { + return nil, fmt.Errorf("failed to marshal to pretty JSON: %w", err) + } + return formatted, nil +}