For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/tech/json.md.
close

JSON

Rspack has built-in support for JSON, and you can import JSON files directly.

Default import

example.json
{
  "foo": "bar"
}
index.js
import json from './example.json';
console.log(json.foo); // "bar"

Named import

In non-.mjs non-strict ESM files, you can directly import properties from JSON.

example.json
{
  "foo": "bar"
}
index.js
import { foo } from './example.json';
console.log(foo); // "bar"

Import attributes

Rspack supports import attributes, and you can use import attributes to import JSON:

index.js
import json from './example.json' with { type: 'json' };
import('./example.json', { with: { type: 'json' } });