Generate .json file other than index.json

I need to generate simple .json file for displaying couple of latest posts.
But index.json is already used by search functionality.
I can’t find any clue in docs

There are several ways to do this, I suspect:

  1. Create a custom output format with baseName to whatever (it defaults to index)
  2. If this is a one-off JSON file, I suspect you would also set the URL in front matter, the output format JSON and proably also a layout for that single MD file.

Check out my theme component example: It creates a micro.json at the domain root level.


This is a single dynamic JSON file, which should show latest posts

hugo v0.49

First i`ve tried use to mess around with outputFormats with no luck (i use code from @kaushalmodi answer as a guide)


  suffixes = ["json"]
  mediaType = "application/json"
  baseName = "micro"
  isPlainText = true

  home = ["HTML", "JSON", "Micro"]

http://localhost:1313/micro.json - 404

Then i`ve tried to add any possible layout:


{{- $micro := "test" -}}
{{- $micro | jsonify -}}

http://localhost:1313/micro.json - 404

I’m desperate, what am I doing wrong?

You would need to share a minimal site source thay anyone can clone and run hugo on. It’s difficult to tell what’s wrong.

Also, does using that micro JSON theme work for you when you follow the README instructions?

Sure, i’ve tried to follow instructions in README as well.
Ok, will try to share some source code

Just make sure that that’s a valid Hugo site i.e. anyone can run hugo on that and reproduce the issue you see.

I have hound a problem
I have in root of content folder, and i defined outputs there. Looks like this file has higher priority then config.toml

That’s another reason why I push everyone to create a minimal reproducible example :smiley:

Obviously! Life would be so miserable if people couldn’t override the output formats for individual pages.