# Range through json object where structure is unknown

**URL:** <https://discourse.gohugo.io/t/range-through-json-object-where-structure-is-unknown/18181>\
**Category:** support\
**Created:** [April 18, 2019, 9:11am UTC](https://discourse.gohugo.io/t/range-through-json-object-where-structure-is-unknown/18181 "2019-04-18T09:11:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zabatonni](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zabatonni/32/7942_2.png) [@zabatonni](https://discourse.gohugo.io/u/zabatonni)\
**Post date:** [April 18, 2019, 9:11am UTC](https://discourse.gohugo.io/t/range-through-json-object-where-structure-is-unknown/18181/1 "2019-04-18T09:11:34Z")

</div>

I need to get all values for key “text” in object of objects and arrays. How can I loop through nested multi-level object?  
Something like while(is\_object($item)) in PHP.

---

<div class="post-metadata">

**Author:** ![zabatonni](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zabatonni/32/7942_2.png) [@zabatonni](https://discourse.gohugo.io/u/zabatonni)\
**Post date:** [April 18, 2019, 9:52am UTC](https://discourse.gohugo.io/t/range-through-json-object-where-structure-is-unknown/18181/2 "2019-04-18T09:52:48Z")

</div>

ok, found solution. I can call same partial over if item is slice or map

```
{{- $output := slice -}}
  {{- range $key,$item := . -}}
    {{- if (or (reflect.IsSlice $item) (reflect.IsMap $item)) -}}
    	{{- $output = $output | append (partial "functions/test" $item) -}}
	{{- else -}}
     	{{- if (eq $key "text") -}}
    		{{- $output = $output | append $item -}}
		{{- end -}}
	{{- end -}}
  {{- end -}}
{{- return $output -}}
```

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [April 18, 2019, 2:11pm UTC](https://discourse.gohugo.io/t/range-through-json-object-where-structure-is-unknown/18181/3 "2019-04-18T14:11:56Z")

</div>

Nice. TIL about these `reflect` functions
