Looping keys from another list in template using getJSON [solved]

I have a JSON field of properties in a dictionary

values = [ {"property1": "value1", "property2": "value2"}, {"property1": "value11", "property2": "value12"} ]

keys = {"property1": "Human Friendly Property name", "property2": "Better Name"}

I have the list of fields in an array. I want to iterate over the first array and use the key/value pairs in the second json to print data.

Can I access the key dynamically in a set dynamically?

{{ $data := getJSON "values.json" }} // does not have the "values = " in the file
{{ $header := getJSON "keys.json" }} // does not have the "keys = " in the file

{{ range $d := $data }}
  {{ range $key, $val := $header }}
    {{ with $header }}
      {{ $val }}: {{ $key }} // cant use $d.key or any other way.
    {{ end }}
  {{ end }}
{{ end }}

The output I am trying to achieve is

Human Friendly Property name: value1
Better Name: value2
Human Friendly Property name: value11
Better Name: value12

Solved it with index. Found index while looking at other problem in this forum :relieved:

{{ range $key, $val := $header }}
  {{ $val }}: {{ index $d $key }}
{{ end }}

2 Likes