Skip to content

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.

{
"value": 123,
"value": 456
}

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."
}

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.