Iterate through an array of nested maps(json objects)

#1

hello,
I have in my site.data.artists folder two json docs that i would like to appear on a template.
the structure is like that

{
  "name": "mygroupname",
  "type": "group",
  "decade": "80s",
  "members": [{ "firstname":"peter", "lastname":"myles"}, 
                      {"firstname":"john","lastname":"goodsome"}]
}

i managed to display name,type decade with

{{ range $.Site.Data.artists }}
                 {{.name}}-{{.type}}-{{.decade}}
{{ end }}

but for members which i saw by printing it that is an array of maps i tried the following and didn’t work

{{ range $.Site.Data.artists }}
                 {{.name}}-{{.type}}-{{.decade}}
                    {{ range .members }}
                        range{{$key, $value:= . }}
                               {{$key}} : {{$value}}
                        {{end}}
                    {{ end }}
{{end}}

an in general if i had also more nested objects how would i list them?
thanks

#2

Please read Requesting Help and act accordingly. That makes life easier for you and for the people here giving answers. Tnx a lot.

1 Like
#3

Leo i have searched google before I post my question and I have spend more than 10 hours reading the documents. I have also programming experience in many languages.
You could just pointed out I have a syntax error, instead of preaching me about reading help first.
Anyway, I solved my problem this morning just by looking the code. range should be inside {{ }} of-course.

#4

My post was not meant as an offense. Sorry if you perceived it that way.

Anyway I believe it’s even though a valid post because nobody can look behind your question. People here have a great attitude to help and for some reason the rules were developed. So please take it that way.