golang struct type을 JSON으로 Print 하기
2023. 3. 29.
package main import ( "encoding/json" "fmt" ) type Person struct { Name string Age int } func main() { myStruct := Person{"dvwy", 145} fmt.Println("=======") fmt.Println(myStruct) fmt.Println(prettyPrint(myStruct)) } func prettyPrint(i interface{}) string { s, _ := json.MarshalIndent(i, "", "\t") return string(s) } 결과는 다음과 같습니다. {dvwy 145} { "Name": "dvwy", "Age": 145 } 출처 : https://stackoverflo..