[solved] Proper way to format a array in root yaml

I’ve been using .json in connexion with the data dir to manage small info I need for my website like social links for exemple. I’ve been willing to switch to yaml since the beginning because it’s easier to write, read and maintain (not so sure now).

But I cannot figure out a way to do this proper:
I used this online converter to make sure I did this right. That is the content of /data/socials.yaml which I retrieve with .Site.Data.socials :

- Name: Twitter
  URL: https://twitter.com/regisphilibert
  Icon: twitter
- Name: GitHub
  URL: https://github.com/regisphilibert
  Icon: github
- Name: CodePen
  URL: https://codepen.io/regisphilibert/
  Icon: codepen
- Name: LinkedIn
  URL: https://www.linkedin.com/in/regisphilibert
  Icon: linkedin

This will systematically trigger this error

yaml: unmarshal errors:
  line 2: cannot unmarshal !!seq into map[string]interface {}

I found this interesting article but cannot really see the connection.

Maybe some ran into the same problem and found a fix or are very knowledgable in yaml :smiley: ?


could the : in https be the problem?

It’s the : after https:. The entire url should be in quotes:

- Name: LinkedIn
  URL: 'https://www.linkedin.com/in/regisphilibert'
  Icon: linkedin

Thanks @brunoamaral and @sjardim I was hopeful reading your replies but nope… same error :frowning:

Haven’t tried, but I am almost sure that you need a “parent key” in the data files. So if you put that whole YAML structure under a parent key foo:, you should be then able to access your data with .Site.Data.Socials.foo.

@kaushalmodi that is what I suspected… but hoped to avoid the following.

{{ range .Site.Data.socials.list }}

This doesn’t make sense… :nerd_face:

Damn! I hate it when people don’t do a thorough search in the discourse! (Which I did without using the good wording)

Anyway thanks @Mikhail this helps, but I still don’t get the same type of object as with my json.

[]interface {}{map[string]interface {}{"Name":"Twitter", "URL":"https://twitter.com/regisphilibert", "Icon":"twitter"}, map[string]interface {}{"Name":...}}


map[string]interface {}{"1":map[interface {}]interface {}{"URL":"https://twitter.com/regisphilibert", "Icon":"twitter", "Name":"Twitter"}, "2":map[interface {}]interface {}{"Icon":"github", "Name":.. }}

Which mean a range first 2 will trigger this:

executing "theme/partials/header.html" at <first 2 .>: error calling first: can't iterate over map[string]interface {}

Still no way to create a simple keyless array in yaml…

I supposed that you omitted the parent on your code, so that’s why I didn’t mention it. It’s required AFAIK.

I have a media.yaml file with:


  - file: BL_circlelogo_color_CMYK.eps
    title: 'Primary logo'
    description: 'The Brightline Initiative logo calls attention with its boldness. Tapered circular strokes connect the two I’s in the Brightline word mark. 
    The primary logo should be used whenever possible.'

  - file: BL_circlelogo_black_1C.eps
    title: 'Primary logo – Black and White'
    description: 'One-color version of the Brightline Initiative primary logo available for circumstances when it is not possible to use the primary color version.'

And I range them using:

{{ range .Site.Data.media.files }}
and so on
{{ end }}

Yes that seems to be the conclusion. Call me psycho but I’ll stick to json just so I don’t have to to range on .Data.socials.items :clown_face:

hehehe you psycho! :wink:

1 Like

Just pointing out the fact that this is now solved by 1fa24177 as of Hugo .37!