Last active
July 13, 2021 03:41
-
-
Save thetonus/8de1033e8b314c17f0b044144f8720d6 to your computer and use it in GitHub Desktop.
Go JSONify Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty prints json with an indent of 4 spaces