0PricingLogin
SQL Academy · Lesson

JSONB vs JSON: When to Use Each

Choose between JSON (text, preserves whitespace) and JSONB (binary, indexable, deduplicated keys) for the right storage.

Two JSON Types in PostgreSQL

  • JSON — stores the exact text you put in
  • JSONB — decomposed binary format, deduplicated keys, indexable

JSON: Text Storage

JSON preserves whitespace, key order, and duplicate keys. Reparse on every read. No GIN indexing. Almost never the right choice for new code.

INSERT INTO docs (data) VALUES ('{"a": 1, "a": 2}'::JSON);
SELECT data->'a' FROM docs;     -- whatever the parser picks

All lessons in this course

  1. JSONB vs JSON: When to Use Each
  2. Path Operators: -> ->> @>
  3. Indexing JSONB with GIN
  4. Modelling: When JSONB Beats Normalisation
← Back to SQL Academy