I have json content as an array of objects in my gatsby site in the format
[{text: 'lorem', image:'some Image'}, {text: 'lorem', image:'some Image'},
… ]
I tried this option, using the list widget in config.yml
- label: "Products Section"
name: "Products"
file: "src/content/productData.json"
fields:
- label: "Products"
name: "productList"
widget: "list"
fields:
- {label: "Caption", name: "text", widget: string,}
- {label: Image, name: image, widget: image}
I receive an empty list with the above option.
Are there any changes that can be made to get it to work? (in either the config or the JSON file structure)
I found part of the answer here:
This appears to be a repeat of
Hi, I have a .json file containing a list of items that populate a menu. The basic structure is:
[
{"slug": "content", "title": "Contact us"},
{"slug": "about", "title": "About us"}
...
]
I’ve tried to recreate this array of objects within the my .yml file like so:
collections:
- name: "menus"
label: "Menus"
files:
- label: "Menu"
name: "menu"
file: "_menu/urls.json"
widget: "list"
fields:
- label: "Menu"
name: "menu"
wi…
So basically netlifycms does not support editing arrays at root level
The issue is open here
But I would still like to know how I can change the json file structure to be able to use the list widget properly
You should name the list like:
"productList": [{text: 'lorem', image:'some Image'}, {text: 'lorem', image:'some Image'}
1 Like
That was fast, I implemented this and it works like a breeze.
Thanks @tomrutgers
This is why I like netlify
2 Likes