Loading...
import config from './config.json' assert { type: 'json' };
console.log(config.theme);import config from './config.json' with { type: 'json' };
console.log(config.theme);Import attributes use the with keyword; the older assert form is not accepted by browsers that support this feature.
import { name } from './data.json', which fails because JSON modules have only a default export.with { type: 'json' }, not the old assert keyword.import(url, { with: { type: 'json' } }).The attribute tells the browser to treat the file as JSON. Without it, the import fails, which stops a server from swapping data for code that runs.
Yes. Pass them as the second argument: await import('./data.json', { with: { type: 'json' } }), then read the data from module.default.