Create a Section only JSON file

I’ve searched on here and found this thread: Create JSON for list section only. I’m trying to do the same thing as the OP wrote in that thread, create a json file for a list section only.

I have the following content structure

content
  |-- products
       |-- _index.md
       |-- product1.md
       |-- product2.md

Inside _index.md, I’ve done as bep suggested in that thread, and added outputs:

+++
date = 2017-10-01T01:08:19+02:00
title = "Products"
outputs = ["HTML",  "RSS",  "JSON"]
+++

I’ve then created a json file, index.json, in Layouts > Products > index.json. I would assume that I should then be able to access the json file by visiting: http://localhost:1313/products/index.json but that doesn’t work so I must be missing something?

Did you add this to your config.toml as well?

[outputs]
  section = ["HTML", "RSS", "JSON"]

Just added it to config as per your message, but http://localhost:1313/products/index.json still gives a 404 page not found.

Can you share your project? Or create a small sample that replicates your issue?

I’ll see what I can do as it’s a private project.

As a side note, I just tried doing the following:

  • I moved index.json fromt Products to Layouts
  • Changed config.toml outputs to home = ["HTML", "RSS", "JSON"] instead of section.

This renders the json file via http://localhost:1313/index.json so that works. Now it’s just to get it to work for a section only.

I just got it to work after using the plug and run method, basically try everything until something works approach :stuck_out_tongue_winking_eye:

Here’s the solution

content
  |-- products
       |-- _index.md
       |-- product1.md
       |-- product2.md

_index.md
    +++
    date = 2017-10-01T01:08:19+02:00
    title = "Products"
    outputs = ["HTML",  "RSS",  "JSON"]
    +++

Layouts
  |-- Products
         |-- list.json

Just needed to change the name on the json file from index to list. It’s enough to list the outputs in _index.html, not needed in config.toml. Appreciate the help.