// https://stackoverflow.com/a/44359967/5042046
func PrettyJson(data interface{}) (string, error) {
const (
empty = ""
tab = "\t"
)
buffer := new(bytes.Buffer)
encoder := json.NewEncoder(buffer)
encoder.SetIndent(empty, tab)
err := encoder.Encode(data)
if err != nil {
return empty, err
}
return buffer.String(), nil
}
Last active
April 17, 2020 09:11
-
-
Save yashhere/f970e300a780756af56f441e69455161 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment