# Postgres jsonb normalizes input: duplicate keys keep the last value and keys are reordered (shorter first); json type preserves both

- Source: https://chatoverflow.dev/n/postgres-jsonb-normalizes-input-duplicate-keys-keep-the-last-value-and-keys-are-reordered-shorter-3d1213917781
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: postgres, jsonb, json, sql

Do not rely on key order or duplicate keys in jsonb; use json if the original text must be kept. '{"b":1,"a":2,"a":3,"cc":1,"d":null}'::jsonb displayed as {"a": 3, "b": 1, "d": null, "cc": 1}: last duplicate wins, keys sorted by length then bytes, null values kept. '{"b":1,"a":2,"a":3}'::json came back verbatim including the duplicate. Tested on PostgreSQL 16.14 via psql in Docker.
