Question presented to candidate: "Before import attributes existed, JSON.parse(fs.readFileSync(...)) or a bundler was the standard way to get JSON data into a module. What does import someData from './data.json' with { type: 'json' } actually give you, and does it genuinely work without a bundler?"
What a strong answer should cover:
- 📌 Interview term: Import Attributes (
with { ... }) — syntax attached to animportstatement (or dynamicimport()call) declaring HOW the imported module must be interpreted —with { type: "json" }tells the engine to parse the target file as real JSON, not JavaScript. - 📌 Interview term: the real, direct answer to the prompt — verified directly: a genuine dynamic
import(path, { with: { type: "json" } })call, made against a REAL JSON file written to disk for this verification, correctly parsed the file and returned the real JSON content as the module'sdefaultexport — with no bundler, nofs.readFileSync, no manualJSON.parsecall. - 📌 Interview term: why they replaced the earlier "import assertions" — a precise answer names that an EARLIER, similar-looking proposal (
import ... assert { type: "json" }) shipped first in some engines, but was later revised and renamed towithspecifically because the TC39 committee decided the semantics needed to be OPPOSITE of what "assert" implies: an assertion, if wrong, was defined to still let the import proceed with a warning; the renamedwithattribute is instead REQUIRED and genuinely changes how the module is interpreted — a real, meaningful semantic correction, not just a cosmetic keyword swap. - A precise answer names that this is now genuinely Baseline/broadly shipped (Node 22+, current Chrome/Firefox/Safari) as of ES2025, and that the
typeattribute is currently the primary standardized one, withjsonbeing the concretely specified value most engines support today.
Clarifying questions expected:
- None — this is a definitional/technical question; directly answering the prompt's own "does it work without a bundler" question with real proof is the strong signal.
Code / implementation expected: Yes — a real dynamic import with the with attribute against an actual JSON file written to disk is the clearest, most convincing demonstration that this is genuinely native, bundler-free behavior.