This content originally appeared on DEV Community and was authored by Andy
Did you know you can now import .json files natively in modern JavaScript without fetch(), bundlers, or dynamic hacks?
Yes, it’s officially supported in all modern browsers and Node.js (v20.6+), and it looks like this:
js
import config from './config.json' assert { type: 'json' };
console.log(config.theme);
That’s it. No more boilerplate. 🙌
âś… Works In:
Chrome, Firefox, Safari, Edge (2024+)
Node.js v20.6+
You just need to set "type": "module" in your package.json
đź§ Why This Is a Game-Changer
Instead of doing:
fetch('/config.json')
.then(res => res.json())
.then(data => console.log(data));
You now just:
import config from './config.json' assert { type: 'json' };
Cleaner syntax. Synchronous. Built-in support.
It’s perfect for:
App configs
Locale files
Static content for blogs and docs
DevOps dashboards
Theme/data presets
`
đź§Ş Common Pitfalls & Fixes
| ❌ Error | ✅ Fix |
|---|---|
Cannot find module |
Check your file path and extension |
Unexpected token |
Make sure the JSON is valid (Use Formatter) |
Module parse failed |
Add assert { type: 'json' } to your import |
CORS error |
Enable CORS or load JSON from the same origin |
`
🛠️ Bonus Tool – Format & Validate Your JSON First
If your JSON file has even one trailing comma, this import will fail.
Before importing, I use this free tool I built to format, validate, and preview JSON quickly:
👉 https://jsonformatter.online
It also supports:
- JSON to CSV, YAML, XML, Markdown
- Download as Excel (XLSX)
- A full JSON Log Viewer for NDJSON & streaming
- Upload or fetch JSON from a URL
Give it a try and let me know what features you’d love to see!
đź”— Read the Full Guide Here
I wrote a full breakdown of how to use native JSON imports, what’s supported, how to structure projects, and common gotchas here:
👉 How to Use Native JSON Imports in JavaScript (2025 Update)
This content originally appeared on DEV Community and was authored by Andy
Andy | Sciencx (2025-07-14T19:43:06+00:00) 🚀 Native JSON Imports in JavaScript Are Here (2025 Guide with Examples). Retrieved from https://www.scien.cx/2025/07/14/%f0%9f%9a%80-native-json-imports-in-javascript-are-here-2025-guide-with-examples/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.