Beginner
cliweb
Importing JSON
JSON files can be imported in JS and TS files using the `import` keyword. This makes including static data in a library much easier.
JSON files can be imported in JS and TS modules. When doing so, you need to specify the "json" import assertion type.
./main.ts
import file from "./version.json" assert { type: "json" };
console.log(file.version);
Dynamic imports are also supported.
./main.ts
const module = await import("./version.json", {
assert: { type: "json" },
});
console.log(module.default.version);
./version.json
{
"version": "1.0.0"
}