duplicate JSON object key value: “…”
SQLSTATE 22030 condition duplicate_json_object_key_value class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.
Symptoms
A JSON value being parsed into jsonb (with duplicate-key checking) contained the same object key twice. PostgreSQL raises SQLSTATE 22030 (duplicate_json_object_key_value).
- A JSON object has a repeated key.
- Raised when strict duplicate-key checking is in effect.
- Common with hand-built or merged JSON.
What the server log shows
ERROR: duplicate JSON object key value: "id"
Why PostgreSQL raises this — what the manual says
Section 9.16 JSON Functions and Operators:
“If WITH UNIQUE is specified, the expression must not contain any duplicate object keys.”
While jsonb normally keeps only the last value for a duplicate key, builder functions invoked with key-uniqueness checking reject duplicates outright. Encountering a repeated key under that check yields 22030.
Common causes
- A JSON object literal with the same key listed twice.
- Merging objects that share keys with unique-key checking on.
- A JSON-building function called with duplicate keys.
How to fix it
- Remove the duplicate key so each key appears once.
- If last-wins behaviour is acceptable, cast to
jsonbwithout unique-key checking. - De-duplicate keys before building the JSON object.
Related & next steps
Reference: PostgreSQL 18 Section 9.16 “JSON Functions”.