# CSV/JSON files as basis for posts

**URL:** <https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802>\
**Category:** support\
**Created:** [November 28, 2021, 9:01pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802 "2021-11-28T21:01:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ramon/32/11980_2.png) [@Ramon](https://discourse.gohugo.io/u/Ramon)\
**Post date:** [November 28, 2021, 9:01pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/1 "2021-11-28T21:01:23Z")

</div>

I’ve collected roughly 750+ recipe cards (printed in Germany in the '70). It was called Heidis Koch Klub (Heidi’s cooking club).

 ![IMG_1539](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/2/2983a5671c11a4d730d94b773178ea820146ab9e.jpeg)

With some help from Nanonets for helping with OCR of the text on them, I have collected a lot of JSON files. I want to publish the recipes as a pet project and as a way to liberate a lot of great recipes from paper.

I found this resource on [data templates](https://gohugo.io/templates/data-templates/); I can’t seem to get it working. With this step, it gives an error. (it’s below the code). I feel that I am very close to understanding how this works.

I have [these JSON files] with the recipes. My goal is to have a post per recipe and the ability to browser on a tag (dessert, starter, etc). [Demo JSON file](https://github.com/Heidiskochklub/Heidiskochklub.github.io/blob/main/demo.json).

Questions

- Where do I place the code below? I’ve tried it with single and that resulted in the error below.
- Any pointers on how to start with publishing posts with recipes are more than welcome!

```auto
{{ range $.Site.Data.jazz.bass }}
   {{ partial "artist.html" . }}
{{ end }}

```

```auto
Rebuild failed:

Failed to render pages: render of "page" failed: "/Users/x/Desktop/HKK/HKK/themes/Blonde/layouts/post/single.html:3:6": execute of template failed: template: post/single.html:3:6: executing "post/single.html" at <partial "artist.html" .>: error calling partial: partial "artist.html" not found

```

Hugo env

```auto
hugo v0.89.4+extended darwin/amd64 BuildDate=unknown
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.17.2"

```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [November 28, 2021, 9:21pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/2 "2021-11-28T21:21:59Z")

</div>

> [@Ramon](#):
>
> Where do I place the code below? I’ve tried it with single and that resulted in the error below.

The natural place for the code is at `single.html`

> [@Ramon](#):
>
> ` {{ partial "artist.html" . }}`

As per the error message that partial is not found. You need to define it under `/layouts/partials/artist.html` for the build to succeed.

* * *

One more thing.If you want the JSON files published as individual pages then I suggest that you place them under the `content` folder instead of `data`.

JSON is an [acceptable front matter format](https://gohugo.io/content-management/front-matter#front-matter-formats) for content files in Hugo projects.

But you will need to batch convert them from JSON to MD, since JSON is not an acceptable [content file format](https://gohugo.io/content-management/formats/#list-of-content-formats).

---

<div class="post-metadata">

**Author:** ![Ramon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ramon/32/11980_2.png) [@Ramon](https://discourse.gohugo.io/u/Ramon)\
**Post date:** [November 29, 2021, 8:54pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/3 "2021-11-29T20:54:46Z")

</div>

Thanks, this was extremely helpful!

I now can access the information from the example .json file from [the data template](https://gohugo.io/templates/data-templates/). See the attached screenshot;

 ![Screenshot 2021-11-29 at 21.54.04](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/4/4a6a4dec63050cc20cb241f04f0da95fc3f55739.png)

Any pointers on how I can structure the posts so that they will all display a desperate recipe (input JSON or CSV)? I can collect the recipes based on the type (dessert, starter).

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [November 30, 2021, 5:53am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/4 "2021-11-30T05:53:42Z")

</div>

> [@Ramon](#):
>
> how I can structure the posts so that they will all display a desperate recipe (input JSON or CSV)? I can collect the recipes based on the type (dessert, starter).

Unfortunately Hugo does not currently support generating pages from data files.

The way you described the issue originally it seemed like you had a separate data file for each recipe. That is why above I suggested that you move the files in the content folder and convert them to MD so that you have separate pages.

The only way to generate separate pages would be to split the JSON (or CSV) with a third party script and then perhaps it would be best to move these files (after converting them to MD) in the content directory or perhaps render each recipe with a shortcode.

See this GitHub issue, it contains some user tips about splitting a data file (make sure to expand the hidden comments).

> <https://github.com/gohugoio/hugo/issues/5074>
>
> Currently Hugo handles internal and external data source with getJSON/getCSV whi…ch is great for using data source in a template.
> 
> But Hugo cannot, using a data set of items, build a page for each of them plus related list pages like it does from the content directory files.
> 
> Here is a fresh start on specing this important step in the roadmap.
> 
> As a user, I can only see the configuration aspect of the task.
> 
> I don’t see many configuration tied issues except for the mapping of the key/values collected from the data source and the obvious external or internal endpoint of the data set. The following are suggestions regarding how those configurations could be managed by the users followed by a code block example.
> 
> \### Endpoint/URL/Local file
> 
> Depending on use cases there may be a need of one or several url/path. 
> 
> For many projects, not every page types (post, page etc…) may be built from the same source. Type could be defined from a data source key or as a source parameter.
> 
> I suppose there could be other parameters per sources.
> 
> \### Front Matter mapping
> User must be able to map the keys from the data source to Hugo’s commonly used Front Matter Variables (title, permalink, slug, taxonomies, etc…). 
> Every keys not referenced in the map configuration could be stored as is a user-define Front Matter available in the \`.Params\` object but this should not be default as there maybe way too many.
> 
> \### Example:
> 
> This is a realtor agency, a branch of a bigger one. 
> 
> Their pages are built with hugo's local markdown
> 
> They have an old wordpress site whose \> 100 blog posts they did not want to convert to markdown. So they load those blog posts from a local data file on top of the local Hugo's own markdown posts.
> 
> They use a tier service to create job posts when they need to fill a new position. They want to hosts those job listing on their site though. Their jobs are served by \`https://ourjobs.com/api/client/george-and-son/jobs.json\`
> 
> The most important part of the website are their realty listings. They add their listing to their mother company's own website whose API in turn serves those at \`https://api.mtl-realtors/listings/?branch=george-and-son&status=available\`
> 
> \#### Configuration
> \`\`\`yaml
> title: George and Son (A MTL Realtors Agency)
> 
> dataSources:
> - source: data/old\_site\_posts.json
> contentPath: blog
> mapping: 
> Title: post\_title
> Date: post\_date
> Type: post\_type
> Content: post\_content
> Params.location.city: post\_meta.city
> Params.location.country: post\_meta.country
> 
> - source: https://ourjobs.com/api/client/george-and-son/jobs.json
> contentPath: jobs
> mapping: 
> Title: job\_label
> Content: job\_description
> 
> - source: https://api.mtl-realtors/listings/?branch=george-and-son&status=available
> contentPath: listings/:Type/
> grabAllFrontMatter: true
> mapping: 
> Type: amenity\_kind
> Title: name
> Content: description
> Params.neighbourhood: geo.neighbour
> Params.city: geo.city
> \`\`\`
> 
> \#### Content structure
> This results in a content "shadow" structure. Hard lines dir/files are local, while dashed ones are remote.
> 
> \`\`\`
> content
> ├── \_index.md
> ├── about.md
> ├── contact.md
> ├── blog
> │ ├─── happy-halloween.md
> │ ├─── merry-christmas.md
> │ ├- - nice-summer
> │ └- - hello-world
> ├- -listings
> │ ├- - appartment
> │ │ ├- - opportunity-studio
> │ │ ├- - mile-end-condo
> │ │ └- - downtown-tower-1
> │ └- - house
> │ └- - cottage-green
> └- - jobs
> ├- - marketing-director
> └- - accountant-internship
> \`\`\`

---

<div class="post-metadata">

**Author:** ![Ramon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ramon/32/11980_2.png) [@Ramon](https://discourse.gohugo.io/u/Ramon)\
**Post date:** [November 30, 2021, 7:30am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/5 "2021-11-30T07:30:44Z")

</div>

> The way you described the issue originally it seemed like you had a separate data file for each recipe. That is why above I suggested that you move the files in the content folder and convert them to MD so that you have separate pages.

That’s still the case, I have the recipes as CSV files, without a lot of effort, I can also translate them to a JSON format.

I’ll look into a bulk action from CSV to Markdown. Thanks for the link to the issue. It’s a massive thread!

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [November 30, 2021, 7:58am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/6 "2021-11-30T07:58:37Z")

</div>

> [@Ramon](#):
>
> It’s a massive thread!

There is also another related issue: [Pages from data, take 5 · Issue #6310 · gohugoio/hugo · GitHub](https://github.com/gohugoio/hugo/issues/6310)

Pages from Data is the single most requested feature in Hugo.

Hopefully one day it will be possible, but until then we have to use other tools to achieve it.

---

<div class="post-metadata">

**Author:** ![Ramon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ramon/32/11980_2.png) [@Ramon](https://discourse.gohugo.io/u/Ramon)\
**Post date:** [December 1, 2021, 8:45pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/7 "2021-12-01T20:45:20Z")

</div>

To bad, I think I need to switch to Jekyll. That has native support for it … to bad.

---

<div class="post-metadata">

**Author:** ![nfriedli](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/nfriedli/32/26027_2.png) [@nfriedli](https://discourse.gohugo.io/u/nfriedli)\
**Post date:** [December 2, 2021, 8:52am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/8 "2021-12-02T08:52:20Z")

</div>

You can use Eleventy, too 😉

The pagination feature is your friend: [Create Pages From Data—Eleventy, a simpler static site generator.](https://www.11ty.dev/docs/pages-from-data/)

[Forum is closed but @alexandros and @jmooring continue the thread ?!]

---

<div class="post-metadata">

**Author:** ![Ramon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ramon/32/11980_2.png) [@Ramon](https://discourse.gohugo.io/u/Ramon)\
**Post date:** [December 2, 2021, 10:14am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/9 "2021-12-02T10:14:07Z")

</div>

Oh this is cool! Let me try if I can get this working 🙂

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 10:19am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/10 "2021-12-02T10:19:39Z")

</div>

Closed on December 2, 2021, 10:19am UTC



---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 10:20am UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/11 "2021-12-02T10:20:35Z")

</div>

Good.  
However may I remind everyone that this is the Hugo forum.  
You can have this discussion elsewhere.  
Thank you.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [December 2, 2021, 3:48pm UTC](https://discourse.gohugo.io/t/csv-json-files-as-basis-for-posts/35802/12 "2021-12-02T15:48:21Z")

</div>

@Ramon Sorry to see you go. Please reach out if you want to try Hugo again. Converting your 750 JSON files to usable content is a trivial exercise.
