The relational + document hybrid
JSONB is PostgreSQL's binary-encoded JSON type. Unlike JSON (which stores text verbatim), JSONB parses on insert into a fast binary form, supports indexing (GIN), and offers a rich set of operators. It is the answer to most "do I need MongoDB?" questions.
The operators worth memorising
->field access (returns JSONB):data->'user'.->>field access as TEXT:data->>'name'.@>contains:data @> '{"type":"click"}'.?key exists:data ? 'email'.jsonb_path_exists(data, '$.orders[*] ? (@.total > 100)')SQL/JSON path queries.
When to use JSONB and when not to
Reach for JSONB when the sub-object's shape genuinely varies (event payloads, third-party API responses, settings blobs). Avoid JSONB as a way to dodge schema design — if every row has the same five fields, those should be real columns with proper types and constraints.