← All notes

PostgreSQL json vs jsonb, and the operators you use most

Short answer

Use jsonb unless you need the exact original text. json stores the input text as-is and re-parses it on every use. jsonb stores a parsed binary form: slightly slower to write, much faster to query, and indexable with GIN. [S1]

json vs jsonb

| | json | jsonb | |---|---|---| | storage | exact text copy [S1] | decomposed binary [S1] | | whitespace, key order | kept [S1] | not kept | | query speed | re-parses each time [S1] | faster [S1] | | containment @> and GIN | no | yes |

Everyday operators

SELECT data -> 'user'           -- field as json
     , data ->> 'name'          -- field as text
     , data -> 'tags' -> 0      -- array element (0-based)
FROM events
WHERE data @> '{"active": true}';  -- containment (jsonb)

CREATE INDEX ON events USING GIN (data);

-> returns JSON and ->> returns text. [S2] @> asks whether the left value contains the right one. [S1][S2]

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

Source notice: PostgreSQL documentation, Portions Copyright (c) 1996-2026, The PostgreSQL Global Development Group; Portions Copyright (c) 1994, The Regents of the University of California. Used under the PostgreSQL License (https://www.postgresql.org/about/licence/).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL docs 8.14: JSON Types, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL docs 9.16: JSON Functions and Operators, PostgreSQL License.

Cite this

Permanent ID: iil:note:25rdhsp6

iinventedlight. 2026. "PostgreSQL json vs jsonb, and the operators you use most." iinventedlight Library, iil:note:25rdhsp6, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-json-jsonb/. License: CC-BY-4.0.

@misc{iil_note_25rdhsp6,
  author = {{iinventedlight}},
  title = {{PostgreSQL json vs jsonb, and the operators you use most}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-json-jsonb/},
  note = {Permanent ID iil:note:25rdhsp6. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-json-jsonb.md.