# prefer-json-import

Rule `unicorn/prefer-json-import`. Prefer JSON imports over reading and parsing JSON files.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2033 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-json-import` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-json-import.md) |

## Code examples

### Incorrect: the rule reports this

```js
const data = JSON.parse(fs.readFileSync('./data.json', 'utf8'));
```

```js
const settings = JSON.parse(await fs.promises.readFile(new URL('./settings.json', import.meta.url), 'utf8'));
```

```js
const data = require('./data.json');
```

### Correct: the rule accepts this

```js
import data from './data.json' with {type: 'json'};
```

```js
import settings from './settings.json' with {type: 'json'};
```

```js
const dynamicData = JSON.parse(fs.readFileSync(filename, 'utf8'));
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-json-import": "error",
    },
  },
];
```

## Related rules

- [unicorn/prefer-iterator-concat](https://lintradar.dev/rules/unicorn/prefer-iterator-concat.md): Prefer `Iterator.concat(…)` over temporary spread arrays.
- [unicorn/prefer-error-is-error](https://lintradar.dev/rules/unicorn/prefer-error-is-error.md): Prefer `Error.isError()` when checking for errors.
- [unicorn/prefer-regexp-escape](https://lintradar.dev/rules/unicorn/prefer-regexp-escape.md): Prefer `RegExp.escape()` for escaping strings to use in regular expressions.
- [unicorn/prefer-dispose](https://lintradar.dev/rules/unicorn/prefer-dispose.md): Prefer using `using`/`await using` over manual `try`/`finally` resource disposal.
- [unicorn/prefer-short-arrow-method](https://lintradar.dev/rules/unicorn/prefer-short-arrow-method.md): Prefer arrow function properties over methods with a single return.
- [unicorn/no-unused-properties](https://lintradar.dev/rules/unicorn/no-unused-properties.md): Disallow unused object properties.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-json-import. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
