
"With import attributes, the platform can handle JSON modules directly. No transforms, no custom loaders, no build-time sleight of hand. Just the runtime: import config from "./config.json" with { type: "json" }; And dynamically: const mod = await import("./config.json", { with: { type: "json" } });"
"By requiring: import data from "./data.json" with { type: "json" }; we're making a clear contract with the runtime: This file is structured data. Parse it as JSON. Don't execute it. Removing that guesswork is what makes this behave the same way everywhere."
"When you import JSON with attributes: import config from "./config.json" with { type: "json" }; you get a default export containing the parsed JSON. It behaves like any other ES module: Parsed once, Cached like any other module, Added to the module graph, Shared across every place that imports it."
JavaScript now supports JSON as a first-class module type through import attributes. Previously, bundlers transformed JSON imports at build time to simulate native module syntax. The new standard requires explicit type declaration using `with { type: "json" }` in both static and dynamic imports. This syntax removes ambiguity about how the runtime should handle the file—parsing it as data rather than executable code. The explicit contract prevents security issues and ensures consistent behavior across environments. Imported JSON is parsed once, cached like other modules, and shared across all imports, integrating seamlessly into the module graph.
Read at Allthingssmitty
Unable to calculate read time
Collection
[
|
...
]