DEV Community

Discussion on: Creating JSON Files with Eleventy

zulvkr profile image

Nice post.

I did this long ago with custom JSON.stringify() 11ty filter. The code is very clean, but it will print all posts object properties.

{{ collections.posts | JSONstringify | safe}}
Enter fullscreen mode Exit fullscreen mode

As a solution, maybe make another 11ty filter to filter the object, or combine it with this post approach to print only specific data.

I also inline the JSON as object within <script> tag since the data is specific to a page, this way no need for additional api call.

mattwaler profile image
Matt Waler Author

This is super clever!