Skip to content

Instantly share code, notes, and snippets.

@thetonus
Last active July 13, 2021 03:41
Show Gist options
  • Save thetonus/8de1033e8b314c17f0b044144f8720d6 to your computer and use it in GitHub Desktop.
Save thetonus/8de1033e8b314c17f0b044144f8720d6 to your computer and use it in GitHub Desktop.
Go JSONify Helper
func Jsonify(input interface{}) (string, error) {
var stringifiedJson string
var prettyJson bytes.Buffer
body, err := json.Marshal(input)
if err != nil {
return stringifiedJson, err
}
err = json.Indent(&prettyJson, body, "", " ")
if err != nil {
return stringifiedJson, err
}
stringifiedJson = string(prettyJson.Bytes())
return stringifiedJson, err
}
@thetonus
Copy link
Author

Pretty prints json with an indent of 4 spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment