package main import ( "encoding/json" "fmt" "html/template" "log" "os" ) type Testy struct { Flag *bool `json:"flag"` Cake *[]string `json:"cake"` } const TEXT = `{ "cake": [ "one", "two", "three" ] }` const TEMPLATE = `Flag is: {{if .Flag}}{{.Flag}}{{else}}[none]{{end}} Cake is: {{if .Cake}}{{range .Cake}}{{.}} {{end}}{{else}}[none]{{end}} ` func main() { var t Testy json.Unmarshal([]byte(TEXT), &t) tmpl, err := template.New("mytemplate").Parse(TEMPLATE) if err != nil { log.Fatal(err) } tmpl.Execute(os.Stdout, t) b, err := json.Marshal(t) if err != nil { log.Fatal(err) } fmt.Println(string(b)) }