unicorn/prefer-json-import
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-json-import": "error",
},
},
];const data = JSON.parse(fs.readFileSync('./data.json', 'utf8'));const settings = JSON.parse(await fs.promises.readFile(new URL('./settings.json', import.meta.url), 'utf8'));const data = require('./data.json');import data from './data.json' with {type: 'json'};import settings from './settings.json' with {type: 'json'};const dynamicData = JSON.parse(fs.readFileSync(filename, 'utf8'));Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
unicorn/prefer-json-import
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-json-import": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer Iterator.concat(…) over temporary spread arrays.
Prefer RegExp.escape() for escaping strings to use in regular expressions.
Prefer using using/await using over manual try/finally resource disposal.
Prefer arrow function properties over methods with a single return.