New to Next js, Local Json fetching
Unanswered
Western thatching ant posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
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
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
you just import it?
import data from "./test.json";
export default function Page() {
return <div>{data.name}</div>;
}
{
"name": "john doe"
}
![Image](https://cdn.discordapp.com/attachments/1123485906289049661/1123640310937952346/image.png)
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Whippet
in what location did you put the .json file?
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Whippet
more general question, is there a convention where json file should be in?
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
Same directory, i use colocation as described in https://nextjs.org/docs/app/building-your-application/routing/colocation
![Avatar](https://cdn.discordapp.com/embed/avatars/0.png)
Western thatching antOP
Thanks a lot
@joulev