![Thomas Steiner](https://web.dev/images/authors/thomassteiner.jpg) Thomas Steiner [GitHub](https://github.com/tomayac) [LinkedIn](https://www.linkedin.com/in/thomassteinerlinkedin) [Mastodon](https://toot.cafe/@tomayac) [Bluesky](https://bsky.app/profile/tomayac.com) [Homepage](https://blog.tomayac.com/)


Published: June 18, 2025

<br />

If you want to import a JSON file in a JavaScript module, you previously had to
go through hoops like embedding JSON in JavaScript just so you can use a regular
`import` statement, or downloading a file with `fetch()` and then calling
`Response.json()`. This is a problem that is now solved in all modern browsers
thanks to [JSON module scripts](https://github.com/tc39/proposal-json-modules)
and [import attributes](https://github.com/tc39/proposal-import-attributes/).

<iframe src="https:///frame/blog/json-imports-baseline-newly-available/index_643c4d5711c460a324597af73c73db50f40e3cefcc1f300b2bab0b0e6152cb92.frame" class="framebox inherit-locale " allow="clipboard-write https://" allowfullscreen is-upgraded></iframe>

The following sample shows how a JSON module script can be imported from inside
a JavaScript module script:

```javascript
import astronomyPictureOfTheDay from "./apod.json" with { type: "json" };

const {explanation, title, url} = astronomyPictureOfTheDay;

document.querySelector('h2').textContent = title;
document.querySelector('figcaption').textContent = explanation;
Object.assign(document.querySelector('img'), { src: url, alt: title });
```

There's no `JSON.parse()` needed, the JSON is parsed and ready to go right after
the `import`. This works because the browser knows beforehand that it's dealing
with JSON, which you declare with the import attribute `with { type: "json"
}`.
<iframe src="https://chrome.dev/json-module-imports/" style="width: 100%; height: 800px;"></iframe>

Check out this
[live demo of JSON module imports](https://chrome.dev/json-module-imports/) that
uses the code from the previous listing.

MIME type checking for module scripts is strict. In order for the fetch of the
JSON module script to succeed, the HTTP response must have a JSON MIME type, for
example `Content-Type: application/json`.

If the `with { type: "json" }` part of the statement is omitted, the browser
assumes that the intent is to import a JavaScript module script, and the fetch
will fail if the HTTP response has a MIME type that is not a JavaScript MIME
type.

You can
[read more about JSON module script processing](https://html.spec.whatwg.org/#json-module-script)
in the HTML spec.