Β© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Lorenzo Barberis Canonico
Hey everyone, does anyone know how to load a local json file with React? I'm using Babel and Watchify.
I have tried 'import MyData from "json!./data.json"' already.
Sebastian
Do you have sample in GitHub? Maybe try import * as myJson from ... also try without json! if you,re using webpack 2 or higher
Oh wow I just realized what the issue was: the file needs to be in the JS folder. I was placing it in JSX so that's why it wasn't finding it.
import MyData from "./data.json" works!
Thank you again for the help
I recommend to add a entry in the resolve section of the webpack config pointing to the root folder like this, so you can avoid relative paths
... resolve: { modules: [SRC_DIR, 'node_modules'], extensions: ['.js', '.jsx', '.css', '.html', '.scss', '.less', '.json'], alias: { '@': path.resolve(SRC_DIR, 'js'), '#': SRC_DIR, config: path.resolve(SRC_DIR, 'config.js'), root: path.resolve(__dirname) } }, ...
Sebastian
Do you have sample in GitHub? Maybe try import * as myJson from ... also try without json! if you,re using webpack 2 or higher