Skip to content

Instantly share code, notes, and snippets.

@trietphm
Created April 24, 2016 06:32
Show Gist options
  • Save trietphm/c2462eecaa5f9fe3f4de227257edc525 to your computer and use it in GitHub Desktop.
Save trietphm/c2462eecaa5f9fe3f4de227257edc525 to your computer and use it in GitHub Desktop.
Log a json struct golang with indent in console
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