Skip to content

Commit

Permalink
go/oasis-node/cmd/common: Add PrettyJSONMarshal() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Sep 17, 2021
1 parent 1f26390 commit 84c2e34
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions go/oasis-node/cmd/common/json.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 84c2e34

Please sign in to comment.