# 22030 — duplicate_json_object_key_value

> Source-backed reference for PostgreSQL SQLSTATE 22030.
---

# 22030

## At a glance {#at-a-glance}
A JSON object construction encountered a duplicate key. The fixed unique-key JSON builder and aggregate paths report `duplicate JSON object key value: %s`; JSONB finalization has a related variant.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| Field | Value |
| --- | --- |
| SQLSTATE | `22030` |
| Condition | `duplicate_json_object_key_value` |
| Status | `active` |
| Known present by | `12.0` |
| Locked snapshots | `12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3` |
| Macros | `ERRCODE_DUPLICATE_JSON_OBJECT_KEY_VALUE` |
| Aliases | `—` |

<!-- source facts: data/errcodes/22030.json -->
<!-- END SQLSTATE FACTS -->

## Messages {#messages}
The unique-key paths use these primary texts:

| Path | Primary |
| --- | --- |
| JSON builder or aggregate with unique keys | `duplicate JSON object key value: %s` |
| JSONB object finalization or unique-key validation | `duplicate JSON object key value` |

## Meaning {#meaning}
22030 is raised when a JSON object operation has explicitly enabled key uniqueness and sees the same key twice in one object. The JSON builders and object aggregates carry a `unique_keys` flag; their unique variants record keys and raise at insertion or object finalization. Ordinary `json`/`jsonb` input uses the flag as false, and ordinary builders or aggregates do not turn every duplicate in input text into 22030. Strict or absent-on-null variants omit NULL-valued fields from output, but the unique variants retain the key long enough to check it, so a duplicate key can still fail even when its value would be skipped. A NULL key itself is a separate argument error.

## Diagnosis {#diagnosis}
Identify the constructor or aggregate and whether its documented form enforces unique keys. The `%s` primary names the duplicate key for the JSON builder/aggregate path; the JSONB finalization and validation path uses the shorter primary. Distinguish a duplicate-key policy from invalid JSON syntax, a NULL object key, or ordinary `json`/`jsonb` parsing that permits duplicate input under its normal semantics.

## Response {#response}
Apply the owner’s duplicate-key policy: de-duplicate or aggregate upstream values when uniqueness is required, or use a documented non-unique operation only when retaining the operation’s duplicate-key semantics is intentional. Do not solve a NULL key or malformed JSON error by changing the uniqueness flag. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected action.

## Versions {#versions}
The locked catalogue records this condition from 12.0; the fixed JSON and JSONB source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

## Related {#related}
[`22032`](../22032/), [`22023`](../22023/)

## Sources {#sources}
JSON unique-key builders and aggregates are [`src/backend/utils/adt/json.c#L1002-1127`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1002) and [`#L1224-1295`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1224); JSON uniqueness validation is [`#L1810-1853`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/json.c#L1810). JSONB ordinary input leaves uniqueness disabled in [`src/backend/utils/adt/jsonb.c#L74-102`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb.c#L74), while unique builders and finalization are [`#L1125-1163`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb.c#L1125) and [`src/backend/utils/adt/jsonb_util.c#L1952-2005`](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonb_util.c#L1952). The structured [evidence record](../data/evidence/22030.json) retains the unique-key and NULL-skipping boundaries; no natural runtime was run.
