Next.js Discord

Discord Forum

New to Next js, Local Json fetching

Unanswered
Western thatching ant posted this in #help-forum
Open in Discord
Western thatching antOP
Hi guys I'm new to the next js, and I wanted to load data from a local JSON. I wanted to fetch the data and display it in components.jsx file in my components folder. But I'm struggling. to make it happen and tips and suggestions would be appreciated.

10 Replies

Whippet
did you find a solution? im running into the same problem, i tried putting the json into the public folder and reach it like this
  const res = await fetch(`/json/projects.json`);
but it didnt work
Whippet
if you are using page routing this might work https://www.slingacademy.com/article/next-js-read-and-display-data-from-a-local-json-file/ . with app routing i'm not sure yet
{
  "name": "john doe"
}
Whippet
in what location did you put the .json file?
Whippet
more general question, is there a convention where json file should be in?
Western thatching antOP
Thanks a lot
@joulev