9bNine Bits

Postgres JSON vs JSONB: Use jsonb for Most Applications

Use jsonb. The PostgreSQL documentation says most applications should prefer jsonb, which stores a decomposed binary format that is slightly slower to write but significantly faster to process, and which supports indexing. Choose plain json only for specialized needs, such as keeping the exact input text, object key order, or duplicate keys.
Postgres JSON vs JSONB: Use jsonb for Most Applications

json vs jsonb: decision summary

The PostgreSQL documentation states the default plainly: most applications should prefer jsonb, unless there are quite specialized needs, such as legacy assumptions about ordering of object keys. Both types accept almost identical input, and both enforce that every stored value is valid JSON (RFC 7159), which a plain text column does not. The major practical difference is efficiency: json keeps an exact copy of the input text, while jsonb keeps a decomposed binary form.

Criterionjsonjsonb
StorageExact copy of the input textDecomposed binary format
White spacePreservedNot preserved
Object key orderPreservedNot preserved
Duplicate keysAll kept; processing functions treat the last value as operativeOnly the last value kept
Input speedFasterSlightly slower (conversion overhead)
Processing speedInput text is reparsed on each executionSignificantly faster, no reparsing needed
IndexingWhole-document indexing not availableSupports indexing, which the docs call a significant advantage
Unicode escapesChecked for syntax only, whatever the database encodingStricter: rejects characters the database encoding cannot represent, rejects \u0000, requires correct surrogate pairs
Documentation's adviceSpecialized needs onlyPreferred for most applications

Both are ordinary column types, so the choice between them does not change transactional behavior.

Text storage vs decomposed binary storage

A json column stores the input exactly as written, including semantically insignificant white space. Every function or operator that touches a json value must reparse that text on each execution. A jsonb column stores the value already broken down into a binary structure, so later reads skip parsing entirely.

SELECT '{"bar": "baz",  "balance": 7.77, "active": false}'::json;
-- {"bar": "baz",  "balance": 7.77, "active": false}   (spacing and key order preserved)

SELECT '{"bar": "baz",  "balance": 7.77, "active": false}'::jsonb;
-- {"bar": "baz", "active": false, "balance": 7.77}    (extra space removed, key order not kept)

This is the root of every other difference: json optimizes for faithful storage of the input, jsonb for repeated processing.

Key order and duplicate keys

json preserves key order exactly as submitted and keeps every duplicate key. jsonb does neither: it does not preserve key order and, when a key appears more than once, keeps only the last value.

SELECT '{"a":1,"a":2,"b":3}'::json;
-- {"a":1,"a":2,"b":3}   (both "a" entries kept, original order)

SELECT '{"a":1,"a":2,"b":3}'::jsonb;
-- {"a": 2, "b": 3}      (only the last "a" survives)

This matters when a source depends on key order or deliberately repeats keys. If you must reproduce the original structure, json is the only one of the two that preserves it. For ordinary application data, where each key is unique and order carries no meaning, nothing is lost by using jsonb.

Write cost vs read cost

json is the cheaper type to write: Postgres checks that the text is valid JSON and stores it as is. jsonb is slightly slower to write because Postgres has to parse the value and convert it to its binary layout first. That conversion happens once, when the row is inserted or the value is updated.

The cost reverses on read. A json value is reparsed every time a function or operator extracts something from it, so a frequently queried column pays that price repeatedly. A jsonb value is already structured, which the documentation describes as significantly faster to process. Because the input overhead is only slight, a write-heavy column on its own is not a reason to choose json; the documentation's exceptions are specialized needs such as legacy key-order assumptions.

Operators, queries and GIN indexing on jsonb

Extraction with -> and ->> is the everyday way to read a field, and it is the same on both types. Containment and key-existence checks, along with jsonpath matching, are jsonb features, and indexing a whole document is a jsonb feature too. A typical setup looks like this:

CREATE TABLE events (
  id   bigserial PRIMARY KEY,
  data jsonb NOT NULL
);

CREATE INDEX events_data_gin ON events USING gin (data);

-- containment: rows whose document includes this key/value pair
SELECT * FROM events WHERE data @> '{"status": "error"}';

-- extract a field as text
SELECT data->>'user_id' FROM events WHERE data->>'status' = 'error';

The GIN index on data serves document-level searches such as the containment query above. Run EXPLAIN on your own queries to confirm the planner uses it, since a query written in a different shape may not.

If you only ever filter on one field, a B-tree expression index on the extracted value is a smaller alternative, and it works on either type:

CREATE INDEX events_status_idx ON events ((data->>'status'));

It speeds up lookups on that one expression only, not searches across the whole document. PostgreSQL also provides a separate jsonpath type for efficient querying of JSON data.

When plain json is still right

Pick json when the stored text itself is the record and must come back unchanged:

  • The exact input text, including white space, has to survive, for example a raw payload kept for audit or replay.
  • Object key order carries meaning, which is the legacy assumption the documentation names.
  • Duplicate keys must be kept as received.
  • A value is valid JSON but would fail jsonb's stricter Unicode rules, such as a \u0000 escape or an escape for a character the database encoding cannot represent. json checks Unicode escapes only for syntax, so such a value can be stored as json yet fail to convert to jsonb.

Keeping both is also reasonable: a json column for the untouched payload, and a jsonb column (or a jsonb column on a related table) holding the queryable form.

Converting an existing column

Changing a column to jsonb is a single statement, though on a large table it is an expensive operation:

ALTER TABLE events
  ALTER COLUMN data TYPE jsonb USING data::jsonb;

The conversion drops white space and key order, and keeps only the last value of any duplicate key. It can also fail outright if a value contains a Unicode escape jsonb rejects. On a big table, a safer path is to add a new jsonb column, backfill it in batches, keep it in sync during the transition, switch reads over, and then drop the old column. Casting back from jsonb to json cannot restore anything jsonb already discarded.

The behavior described here follows the PostgreSQL 19 documentation, released 19 November 2026.

Common questions

Should I use json or jsonb in Postgres?

Use jsonb. The PostgreSQL documentation says most applications should prefer jsonb, unless there are quite specialized needs, such as legacy assumptions about ordering of object keys. jsonb is slightly slower to input but significantly faster to process, and it supports indexing.

Can I put a GIN index on a json column?

Indexing a whole JSON document is a jsonb feature. For a json column you can still add a B-tree expression index on an extracted field, such as (data->>'status'), but that only speeds up lookups on that one expression.

Does converting json to jsonb lose data?

It can. White space and key order are not kept, and when a key is duplicated only the last value survives. Values containing Unicode escapes that jsonb rejects, such as \u0000, will fail to convert at all.

Is jsonb slower to write than json?

Slightly. The documentation attributes this to added conversion overhead at input time, since the value is parsed into its binary format. That cost is paid once per write, while json pays a reparsing cost on every read.

Sources

  1. PostgreSQL Documentation: JSON Types
  2. PostgreSQL FAQ: current version and release date

About this page

Last reviewed November 26, 2026 by the Nine Bits editors. Read our editorial policy or report an error.