keyDuplicates
Reports unnecessary duplicate keys that override previous values.
✅ This rule is included in the json logical
preset.
Although JSON technically allows duplicate keys, using them is at best confusing. Most JSON parsers will ignore all but the last value for a given key. It’s generally best to ensure that each key in a JSON object is unique.
Examples
Section titled “Examples”{ "value": 123, "value": 456}
{ "value": 456}
Options
Section titled “Options”allowKeys
Section titled “allowKeys”Type:
string[]
Keys to allow duplicates under.
This can be useful for projects that store extra information as comments in JSON files.
json.rules({ keyDuplicates: { allowKeys: ["//"], },});
{ "comment": "First comment.", "comment": "Second comment."}
{ "//": "First comment.", "//": "Second comment."}
When Not To Use It
Section titled “When Not To Use It”If your project is a rare one that intentionally goes against standard conventions for JSON, you can turn off this rule. You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Deno:
no-dupe-keys
- ESLint:
jsonc/no-dupe-keys
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.