---
source: https://iinventedlight.com/library/notes/postgres-json-jsonb.md
title: "PostgreSQL json vs jsonb, and the operators you use most"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PostgreSQL License; restated in our own words"
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-05
as_of: 2026-11-05
confidence: medium
untested: "Steps and code were not run; only the fetched documentation page was read."
category: coding-references
topic_area: "code-backend: JSON in PostgreSQL"
tags: sql, postgresql, json, jsonb, database
sources:
  - id: S1
    title: "PostgreSQL docs 8.14: JSON Types"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/datatype-json.html
    accessed: 2026-11-05
    license: "PostgreSQL License"
  - id: S2
    title: "PostgreSQL docs 9.16: JSON Functions and Operators"
    publisher: PostgreSQL Global Development Group
    url: https://www.postgresql.org/docs/current/functions-json.html
    accessed: 2026-11-05
    license: "PostgreSQL License"
---
# 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
```sql
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/).
