Not Getting keys from Json file using delimit function

Hi there,
I have json file like this :

   "hi-core/bower": {
       "name": "hi-core",
       "dependencies": {
            "showdown": "1.8.6",
           "moment": "2.22.1"

I am trying to fetch the dependencies using a shortcode,which i am getting but i am getting like this:


I used delimit function so that map goes away but 'delimit ’ only gives me the value of the key and not the key itself(i.e just the ‘showdown’)!

Is there any way i can just get the keys of ‘dependencies’?

Any help is appreciated!

You need to use range.

If the map map[showdown-“1.8.6”] is stored in $foo, do:

{{ range $key,$val := $foo }}
    <!-- $key will then hold "showdown" -->
    <!-- $val will hold "1.8.6" -->
{{ end }}

“map[showdown-“1.8.6”]” is just how Go represents the map in string form… it’s not literally stored like that.

1 Like

That worked for me! Thanks :slight_smile:

@kaushalmodi Is it true that i cant use delimit function with range?

I am trying to do this but looks like it doesnt work

{{ range $key,$val := $cur }} 
{{ delimit ($key) ", "  }} 
{{ end }}


It depends what you are applying the delimit function to. It can be applied only to slices/maps. $key in that example is a string; it won’t work there.


May be you need to present that example JSON file and intended output, and ask what Go templating would be needed to go from that JSON to that output.