Import assertions allow us to import JSON as if it were a real JS file.
Input:
// main.js
import dep from "./dep" assert { type: "json" };
console.log(dep);
// dep
{ "key": "value" }
Output:
// main.js
import dep from "./dep"
console.log(dep);
// dep
export default JSON.parse(`{ "key": "value" }`);
I think we can agree on this interpretation of JSON import. My mental model is that it is a runtime "evaluator" that performs JSON.parse
(or just a regular JS object source text, because JSON is JS). Either way, importing with an assertion changed the iterpretation of the imported module.