--- url: "https://web.dev/blog/json-imports-baseline-newly-available" titulek: "JSON module scripts are now Baseline Newly available | Blog | web.dev" h1: "JSON module scripts are now Baseline Newly available Stay organized with collections Save and categorize content based on your preferences." popis: "Thanks to JSON module scripts and import attributes, you can now directly import JSON in JavaScript modules. Both features are now Baseline Newly available." jazyk: "en" kanonicka: "https://web.dev/blog/json-imports-baseline-newly-available" drobecky: ["Blog", "JSON module scripts are now Baseline Newly available"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 21:35:22" znaku: 2492 slov: 352 kodovani: "iso-8859-2" sha256: "6f94e21b88a31e31173f51c071f8a8215a9b785ece6430a0889827bc7c016af7" --- JSON module scripts are now Baseline Newly available Stay organized with collections Save and categorize content based on your preferences. Thomas Steiner Published: June 18, 2025 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/). The following sample shows how a JSON module script can be imported from inside a JavaScript module script: `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" }`. 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. Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2025-06-18 UTC.