JSON

JSON is a first-class citizen with Rspack. You can import it directly, for example:

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' } });