arrow_back
Back

Hugo JSON output: custom list.json and section outputs

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Unlike RSS, JSON output needs a layout and an explicit outputs list.

Section list as JSON

layouts/projects/list.json:

{
  "projects": [
    {{- range $index, $page := (where .Site.RegularPages "Type" "in" "projects") }}
    {{- if $index -}} , {{- end }}
    {
      "url": {{ .Permalink | jsonify }},
      "title": {{ .Title | jsonify }}
    }
    {{- end }}
  ]
}

In content/projects/_index.md:

outputs:
- HTML
- JSON
- RSS

Then open /projects/index.json.

Custom URL caveat

url: /projects.json

If you set url on that section index, Hugo stops rendering the HTML page for it — there is no per-format URL mapping.

When alternative formats are linked in the head (see templates ), the JSON feed appears next to RSS automatically.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Hugo client-side search: Lunr, JSON index, and search UI

arrow_forward