I'm using Eleventy and NetlifyCMS and I want one field that is a string (sepparated by comma) to convert to an array in JSON so I can search individual items in that field from Fuse.js
So I wrote a .njk file that builds a JSON index with all the data I need to search in.
The front matter in .md files from Eleventy:
---
mylistfield: item 1, item 2, item 3
---
Then i'm taking the data to build a JSON file with a .njk file:
---
permalink: '../search.json'
eleventyExcludeFromCollections: true
---
[
{% for post in collections['plantas'] %}
{
"myarrayofitems":"{{ post.data['mylistfield'] }}",
}
{% if loop.last == false %},{% endif %} {% endfor %}
]
Current search.json output:
[
{
"mylistfield":"item 1, item 2, item 3"
}
,
{
"mylistfield":"item 1, item 2, item 3"
}
]
Expected search.json output:
[
{
"mylistfield":["item 1", "item 2", "item 3"]
}
,
{
"mylistfield":["item 1", "item 2", "item 3"]
}
]
The problem is that I get a string separated by comma and I want to split to an array with each item. Is it posible to do that in that Nunjucks file?
Thanks