Duplicate keys
Also called repeated keys
Duplicate keys are the same member name appearing more than once in one JSON object, like {"a": 1, "a": 2}. RFC 8259 says keys should be unique but does not forbid repeats, so the result depends on the parser. JavaScript's JSON.parse keeps the last value, while other parsers may keep the first or throw an error.
In more detail
Duplicate keys are the same name appearing twice in one object, as in {"a": 1, "a": 2}. RFC 8259 says the names within an object should be unique. It does not forbid repeats, but it warns that software receiving them behaves unpredictably.
In practice most parsers keep the last value without any warning. JavaScript's JSON.parse and Python's json module both return {"a": 2} for the example above. Some parsers keep the first value, and strict ones, such as an RFC 8785 canonicalizer, reject the document.
Because the first value is silently lost, duplicates usually point to a bug, such as a merge gone wrong or a hand-edited config file. Treat them as errors and remove them, even when your parser accepts them.
Example
import json
json.loads('{"a": 1, "a": 2}') # {'a': 2}
# Reject duplicates with object_pairs_hook
def no_dupes(pairs):
keys = [k for k, _ in pairs]
if len(keys) != len(set(keys)):
raise ValueError(f"duplicate keys: {keys}")
return dict(pairs)
json.loads('{"a": 1, "a": 2}', object_pairs_hook=no_dupes) # ValueErrorTry it
Learn more in the guide How to fix JSON syntax errors and JSON.parse SyntaxError.
← Back to Duplicate keys in the JSON glossaryUpdated 2026-10-01