Split a JSON array into Markdown files

This is a cross-post from GitHub.

Here is a one-liner, that splits a JSON array into different markdown pages.
The filename is based on the value of the first parameter in each element.
The script depends on jq and it should work in any UNIX environment:

jq -cr '.[] | .filename, .' *.json | awk 'NR%2{f=$0".md";next} {print >f;close(f)}'

Optional step: Script to convert Markdown files to Hugo Page Bundles

This little script can help those who need a quick and simple way to split a data file and consume its contents as Markdown content files in Hugo, while we wait for a native way to handle Pages from Data.

8 Likes