Created
April 24, 2016 06:32
-
-
Save trietphm/c2462eecaa5f9fe3f4de227257edc525 to your computer and use it in GitHub Desktop.
Log a json struct golang with indent in console
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
) | |
func main() { | |
type ColorGroup struct { | |
ID int | |
Name string | |
Colors []string | |
} | |
group := ColorGroup{ | |
ID: 1, | |
Name: "Reds", | |
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, | |
} | |
b, err := json.MarshalIndent(group, "", " ") | |
if err != nil { | |
fmt.Println("error:", err) | |
} | |
os.Stdout.Write(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment