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
- id: C1 claim: PostgreSQL offers two types for storing JSON data: json and jsonb. source: S1 evidence: "PostgreSQL offers two types for storing JSON data: json and jsonb."
- id: C2 claim: Most applications should prefer to store JSON as jsonb. source: S1 evidence: "most applications should prefer to store JSON data as jsonb"
- id: C3 claim: The json type stores an exact copy of the input text. source: S1 evidence: "The json data type stores an exact copy of the input text"
- id: C4 claim: Containment tests whether one jsonb document contains another. source: S1 evidence: "Containment tests whether one jsonb document has contained within it another one."
- id: C5 claim: The ->> operator extracts an array element as text. source: S2 evidence: "element of JSON array, as text."
Sources
- [S1] PostgreSQL docs 8.14: JSON Types. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/datatype-json.html . License: PostgreSQL License. Accessed 2026-11-05.
- [S2] PostgreSQL docs 9.16: JSON Functions and Operators. PostgreSQL Global Development Group. https://www.postgresql.org/docs/current/functions-json.html . License: PostgreSQL License. Accessed 2026-11-05.
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
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.},
}
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.