Last active
October 26, 2022 02:51
-
-
Save vuduongtp/ce5fdceb84bf6f48bc44acc5fdf74112 to your computer and use it in GitHub Desktop.
Golang - Pretty print object as JSON format
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
import ( | |
"encoding/json" | |
"fmt" | |
"reflect" | |
) | |
func PrettyPrint(i interface{}) { | |
fmt.Printf("Type: %s\n", reflect.TypeOf(i)) | |
s, _ := json.MarshalIndent(i, "", "\t") | |
fmt.Println(string(s)) | |
fmt.Println("==============") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment