SQLSTATE 22030 ERROR Class 22: Data Exception

duplicate_json_object_key_value duplicate JSON object key value — 22030

PostgreSQL error “duplicate JSON object key value — 22030” (SQLSTATE 22030): what it means, common causes, and how to fix it.

PG 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A JSON object being built or parsed with unique-key checking contained the same key twice. PostgreSQL raises SQLSTATE 22030 (duplicate_json_object_key_value). This is the errors-new counterpart of the message-keyed JSON key page.

  • 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

Why PostgreSQL raises this — what the manual says

Section 9.16 JSON Functions and Operators:

“If WITH UNIQUE KEYS is specified, there must not be any duplicate key_expression.”

While jsonb normally keeps the last value for a duplicate key, builder functions with key-uniqueness checking reject duplicates outright. A repeated key under that check yields 22030.

Common causes

  • A JSON object 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

  1. Remove the duplicate key so each appears once.
  2. Cast to jsonb without unique-key checking if last-wins is acceptable.
  3. De-duplicate keys before building the object.

Related & next steps

Reference: PostgreSQL 18 Section 9.16 “JSON Functions”.

Was this helpful?