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
![]() |
![]() |
---|---|
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:
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