src/content/docs/linter/rules/use-json-import-attributes.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::note This rule belongs to the project domain. This means that its activation will activate the Biome Scanner to scan the files of your project. Read more about it in the [documentation page](/linter/domains#project) ::: ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/correctness/useJsonImportAttributes`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`project`](/linter/domains#project) ## How to configure ```json title="biome.json" { "linter": { "rules": { "correctness": { "useJsonImportAttributes": "error" } } } }## Description
Enforces the use of `with { type: "json" }` for JSON module imports.
ECMAScript modules can import JSON modules. However, the specific import assertion `with { type: "json" }`
is required to inform the JavaScript runtime that the imported file should be parsed as JSON.
Omitting this assertion can lead to runtime errors or misinterpretation of the imported module.
This rule ensures that all imports of `.json` files include this assertion.
## Examples
### Invalid
```js
import jsonData from './data.json';
import jsonData from './data.json' with { someOtherAttribute: "value" };
import jsonData from './data.json' with { type: "json" };
import jsonData from './data.json' with { type: "json", other: "value" };
import code from './script.js'; // Not a JSON import