Achieve array of strings from list widget, not array of arrays of strings

Hi! I have the following image gallery collection defined in config.yml, taken from the example with fields on the list widget docs.

collections:
  - label: 'Portfolio'
    name: 'portfolio'
    files:
      - label: 'Portfolio images'
        name: 'portfolioImages'
        file: 'src/_data/portfolio.json'
        fields:
          - label: 'Images'
            label_singular: 'image'
            name: 'images'
            widget: 'list'
            collapsed: true
            summary: '{{fields.image}}'
            field: { label: Image, name: image, widget: image }

This creates a json data structure of an array of arrays of a string that looks like:

{
  "images": [
    [
      "https://res.cloudinary.com/blahblahblah0.jpg"
    ],
    [
      "https://res.cloudinary.com/blahblahblah1.jpg"
    ],
}

The data structure I’m really after, is as flat as possible – just an array of strings:

[
  '"https://res.cloudinary.com/blahblahblah0.jpg",
  "https://res.cloudinary.com/blahblahblah1.jpg"
]

But this doesn’t seem to be possible via NetlifyCMS. (Is it??)

If the above structure is not possible, then how to at least achieve an array of strings as an object property?

{
  "images": [
    "https://res.cloudinary.com/blahblahblah0.jpg",
    "https://res.cloudinary.com/blahblahblah1.jpg"
  ]
}

Thanks!

Actually, you have set it up in exactly that format! I’m not sure what’s happening. Try setting your json file to an object with an empty list and try again.

{
  "images": []
}
1 Like

Thanks for the vote of confidence @tomrutgers.

I thought maybe the images were resulted as an array of arrays because multiple images were enabled globally in my media library settings. So I turned them off locally, but still get the same undesired data structure.

Here’s the NetlifyCMS-updated collection data file that shows the problem - Azellaz.com/portfolio.json at bf64950fc93dcf6c0874329cae17e4d5554106ed · brianzelip/Azellaz.com · GitHub

And here’s the NetlifyCMS config file that created it - Azellaz.com/config.yml at bf64950fc93dcf6c0874329cae17e4d5554106ed · brianzelip/Azellaz.com · GitHub

1 Like