Next.js Discord

Discord Forum

Correct way of implementing a static json file

Answered
Forest bachac posted this in #help-forum
Open in Discord
Forest bachacOP
I have a json file containing some data which will never change (corresponding images and names for weather) and I am wondering how I should implement fetching it statically?

- FS?
- Public folder + fetch force cache?
Answered by joulev
If you use typescript,

import data from "./data.json"

If you use JavaScript, I think you need some import assertions.
View full answer

7 Replies

Forest bachacOP
how
or wdym by that
If you use typescript,

import data from "./data.json"

If you use JavaScript, I think you need some import assertions.
Answer
Yeah looks like for JavaScript, the syntax is currently

import fooData from './foo.json' with { type: 'json' };
Forest bachacOP
k
Forest bachacOP
Nevermind