PostgreSQL JSON

How does JSONB handle duplicate keys compared to the JSON type?

JSONB removes duplicate keys keeping only the last value, while JSON preserves all duplicate keys as originally provided. When JSONB processes input with duplicate keys like {"a":1, "a":2}, it stores only {"a":2}. JSON stores the complete text including duplicates. This behavior affects data integrity and application logic. JSONB deduplication happens during insertion, making it consistent but potentially losing data if duplicates contain different information. JSON preserves duplicates but most parsers reading JSON also use last-value-wins semantics. JSONB behavior aligns with JSON specification which does not guarantee duplicate key handling. However, some applications rely on duplicate keys for merging or overlaying configuration. When migrating from JSON to JSONB, duplicate keys silently disappear. Test data has duplicates using our JSON Validator at jsonconsole.com/json-editor to identify potential issues before JSONB migration. For production systems, ensure your JSON generation never produces duplicate keys to avoid cross-type inconsistencies. JSONB approach is cleaner and matches standard parser behavior, making it preferable.
Last updated: December 23, 2025

Still have questions?

Can't find the answer you're looking for? Please reach out to our support team.