{"article":{"slug":"json-vs-jsonb-in-postgresql-size-and-speed-measured","title":"json vs jsonb in PostgreSQL: size and speed, measured","subtitle":null,"summary":"json vs jsonb in PostgreSQL 17 and 18, measured on six document shapes: when jsonb is 23% smaller or 41% larger, read speed, GIN indexes, and what jsonb changes in your data.","content_type":"research","language":"en","canonical_url":"https://now-next.nl/en/insights/postgresql-json-vs-jsonb-measured/","author":{"name":"Chris van Eijk","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Now-Next","url":"https://now-next.nl/","listing_slug":null,"listing":null},"topics":[{"name":"databases","slug":"databases","url":"https://listedarticles.com/topics/databases"},{"name":"postgresql","slug":"postgresql","url":"https://listedarticles.com/topics/postgresql"},{"name":"benchmarks","slug":"benchmarks","url":"https://listedarticles.com/topics/benchmarks"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":3132,"reading_minutes":14,"published_at":"2026-11-09T00:00:00.000Z","added_at":"2026-11-11T17:12:06.455Z","updated_at":"2026-11-11T17:12:06.455Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/json-vs-jsonb-in-postgresql-size-and-speed-measured","markdown_url":"https://listedarticles.com/articles/json-vs-jsonb-in-postgresql-size-and-speed-measured.md","example":false,"citation":"Chris van Eijk, Now-Next. \"json vs jsonb in PostgreSQL: size and speed, measured.\" 9 Nov 2026. https://now-next.nl/en/insights/postgresql-json-vs-jsonb-measured/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://now-next.nl/en/insights/postgresql-json-vs-jsonb-measured/"},"body_markdown":"# json vs jsonb in PostgreSQL: size and speed, measured\n\njson vs jsonb in PostgreSQL 17 and 18, measured on six document shapes: when jsonb is 23% smaller or 41% larger, read speed, GIN, and what it changes.\n\n[Chris van Eijk, Now-Next](https://now-next.nl/en/about/) ·\n9 November 2026\n· 10 min read\n\nNow-Next builds SaaS products and takes over existing ones. [What we build →](https://now-next.nl/en/services/)\n\nWhether `jsonb` takes more room than `json` depends on the JSON you put in, not on the type alone. In PostgreSQL 17.11 and 18.6, which stored every table byte for byte the same size, a million compact documents of about 200 bytes took 17.8% more room as `jsonb`, while the same documents pretty-printed took 3.6% less; across six document shapes, two input forms and two compression methods we measured everything from 22.6% smaller to 40.9% larger. Reading one key with `->>` was 2.7 to 10.6 times faster from `jsonb` in every case we timed, and only `jsonb` can be compared, grouped or indexed for containment at all.\n\nTwo numbers that show up when you search for this point in opposite directions. In the slides of a PGConf.Russia talk from 2015 by Alexander Korotkov, Oleg Bartunov and Teodor Sigaev, 1.25 million bookmarks take 1,374 MB as `jsonb` against 1,322 MB as `json`: “overhead is < 4%”. A benchmark republished on BestHub in September 2026 reports about 888 MB against 1,200 MB for a million rows, 26% smaller. Korotkov’s 4% falls inside the range we measured. The 26% we could not reproduce: we ran the generator printed in that article for a million rows, with `json.dumps` called without arguments as it is there, which writes a space after every comma and colon, and `jsonb` came out 6.7% larger, 653.5 against 612.6 MB. In our own measurements four things decided which way it went: what the documents contain, whether the JSON contains whitespace, whether a document is large enough for PostgreSQL to compress it, and which compression method it uses.\n\n## json vs jsonb at a glance\n\nPostgreSQL 17.11. Size is the whole table including TOAST, after `VACUUM`; the read is `sum(length(doc->>'first'))` over the whole table, without an index:\n\n| Documents | Rows | Average input | `jsonb` vs `json`, pglz (default) | `jsonb` vs `json`, lz4 | Read one key, `json` → `jsonb` |\n| --- | --- | --- | --- | --- | --- |\n| small, compact | 1,000,000 | 203.4 bytes | +17.8% | +17.8% | 1,379 → 204 ms |\n| small, pretty-printed | 1,000,000 | 248.4 bytes | −3.6% | −3.6% | 1,498 → 207 ms |\n| small with long keys, compact | 1,000,000 | 423.4 bytes | +6.3% | +6.3% | not timed |\n| medium, compact | 100,000 | 1,517.9 bytes | −16.6% | −16.6% | 850 → 310 ms |\n| medium, pretty-printed | 100,000 | 2,381.9 bytes | +16.6% | the same | 1,275 → 313 ms |\n| large, compact | 5,000 | 20,532.0 bytes | +33.0% | +22.2% | 541 → 146 ms |\n| large, pretty-printed | 5,000 | 28,829.0 bytes | the same | +0.1% | 604 → 144 ms |\n| flat, 780 random strings, compact | 5,000 | 21,129.0 bytes | −22.6% | −10.4% | 430 → 149 ms |\n| flat, pretty-printed | 5,000 | 24,266.0 bytes | −5.5% | −10.4% | 602 → 149 ms |\n| array of 3,500 integers, compact | 5,000 | 20,692.3 bytes | +3.2% | +40.9% | 791 → 249 ms |\n| array of integers, pretty-printed | 5,000 | 38,216.3 bytes | +1.9% | +20.0% | 868 → 249 ms |\n\nThe read times are from the pglz tables. On PostgreSQL 18.6 they were within 6% of these, except the small `jsonb` tables, which read 6 to 15% faster; `jsonb` was the faster type in every row on both versions.\n\n## The setup\n\nPostgreSQL 17.11 and 18.6 in throwaway containers from the official images, on one machine with an 8-core Ryzen 7 3700X and 62 GiB of memory. `shared_buffers` 2 GB, so every table we queried was read from shared memory; autovacuum, JIT and parallel query off, data checksums on. Six document shapes, generated from a fixed seed:\n\n- **small**: eleven flat keys of short strings, numbers and a boolean, like `{\"first\":\"e6a14425\",\"id\":1,\"status\":\"closed\",\"tag\":\"r520\",\"plan\":\"free\",\"country\":\"NO\",\"score\":28.78,\"active\":true,…}`\n- **small with long keys**: the same values under keys like `subscription_lifecycle_status`\n- **medium**: a nested order with a customer, an address, seven order lines and five events\n- **large**: a customer and 165 line items\n- **flat**: 780 keys with a random 16-character string each, which compresses badly\n- **array of integers**: 3,500 whole numbers between 0 and 99,999\n\nEach shape was written twice from the same values: compact, and pretty-printed with an indent of two, as `JSON.stringify(x, null, 2)` writes it. Each went into four tables, loaded with `COPY`: `json` and `jsonb`, each with `default_toast_compression` `pglz` (the default) and `lz4`. Timings were taken inside the server: for queries the median of five runs after one untimed warm-up, for loads, index builds and updates the median of three. The scripts are linked at the end.\n\n## Is jsonb bigger than json?\n\nBefore compression, always bigger than compact JSON; on disk, it depends. The type stores a parsed document: a header for every key and value, keys sorted, numbers as `numeric`. To see that layer on its own, we also measured the size of each document as an uncompressed value, with `pg_column_size(doc::json)` and `pg_column_size(doc::jsonb)` over all rows, on both versions:\n\n| Documents | `json`, compact | `json`, pretty-printed | `jsonb`, either input | `jsonb` vs compact | `jsonb` vs pretty-printed |\n| --- | --- | --- | --- | --- | --- |\n| small | 207.4 bytes | 252.4 bytes | 245.9 bytes | +18.5% | −2.6% |\n| small with long keys | 427.4 bytes | — | 465.8 bytes | +9.0% | — |\n| medium | 1,521.9 bytes | 2,385.9 bytes | 2,071.9 bytes | +36.1% | −13.2% |\n| large | 20,536.0 bytes | 28,833.0 bytes | 26,476.1 bytes | +28.9% | −8.2% |\n| flat | 21,133.0 bytes | 24,270.0 bytes | 22,704.0 bytes | +7.4% | −6.5% |\n| array of integers | 20,696.3 bytes | 38,220.3 bytes | 54,701.6 bytes | +164.3% | +43.1% |\n\nThree things follow from that table and from the stored sizes above.\n\n**The overhead is per key, not per byte.** The small documents grew by 38.5 bytes in `jsonb`, the same documents with long keys by 38.4: 18.5% and 9.0%. Our small documents were not compressed, so the overhead carried over to disk: 17.8% and 6.3% larger tables, a little less than per value because every row also has a header of its own.\n\n**Whitespace is gone in `jsonb`, and that can pay for the headers.** `json` keeps your text as it arrived, indentation and all; `jsonb` came out the same size from both inputs, and before compression smaller than pretty-printed `json` in every shape except the integer array. Integers are where `jsonb` grows most: 3,500 of them took 54.7 KB against 20.7 KB as compact text.\n\n**Compression reorders everything.** PostgreSQL tries to compress a value once a row gets larger than about 2 kB, according to the documentation on TOAST. The compact medium document, 1,521.9 bytes as `json`, stayed under that and was stored uncompressed in all 100,000 rows. The same document as `jsonb`, 2,071.9 bytes, went over, and was compressed in all 100,000 rows, to 1,149.7 bytes with pglz. That is how a type that is 36% larger before compression ends up 16.6% smaller on disk. On the flat documents pglz left the compact `json` text uncompressed in all 5,000 rows, but did compress the `jsonb` form. Once both sides were compressed, `jsonb` was as large or larger in ten of the thirteen cases, up to 33.0% for the large compact documents with pglz and 22.2% with lz4; only the flat documents with random strings were 5.5 to 10.4% smaller as `jsonb`. Whitespace compresses well, so for pretty-printed medium documents the advantage turned around: 13.2% smaller before compression, 16.6% larger after pglz. And the method matters per shape: for the integer array, lz4 made `jsonb` 40.9% larger, pglz 3.2%.\n\nBytes per medium document, 100,000 orders, before compression and as stored with pglz: PostgreSQL 17.11 and 18.6\n\n| Type, input and state | Bytes per document |\n| --- | --- |\n| `json`, compact, before compression | 1,521.9 |\n| `json`, compact, stored: not compressed | 1,521.9 |\n| `json`, pretty-printed, before compression | 2,385.9 |\n| `json`, pretty-printed, stored | 1,018.7 |\n| `jsonb`, either input, before compression | 2,071.9 |\n| `jsonb`, either input, stored | 1,149.7 |\n\nBar length is linear, against the largest value. Grey is the value before compression, violet the average stored value in the table, both measured with `pg_column_size`. Only compact `json` stays under the threshold of about 2 kB and is stored as typed; the two larger forms get compressed and end up smaller.\n\nThe result is a ranking that turns the uncompressed one upside down. On disk, pretty-printed `json` was the smallest of the three, 117.5 MB for the table, then `jsonb` with 136.9 to 137.0 MB, and compact `json`, the smallest before compression, was the largest with 164.2 MB.\n\nSo for a quick estimate: small documents are 6 to 18% larger as `jsonb` if your application sends compact JSON, and slightly smaller if it sends pretty-printed JSON. Above about 2 kB, measure your own documents.\n\n## Is jsonb faster to read?\n\nYes, in every case we timed. Extracting one key with `->>` from the whole table, without an index, was 2.7 to 10.5 times faster from `jsonb` on PostgreSQL 17.11 and 2.8 to 10.6 times on 18.6. `json` has to parse the text again on every read. It made no difference whether we asked for the key written first or the one written last: 1,379 against 1,397 ms for `json` on the small table, 204 against 200 ms for `jsonb`.\n\nFor documents that PostgreSQL compresses, the compression method mattered as much as the type. Reading one key from the medium `jsonb` documents took 310 ms with pglz and 96 ms with lz4; from the flat ones 149 against 42 ms. Before `->>` can look inside a compressed document, PostgreSQL has to decompress it, and lz4 was the faster of the two at that. It is not free on disk: the `jsonb` tables were 24.8% larger with lz4 than with pglz for the large documents and 45.1% for the integer array, the same size for the medium ones and 5.3% smaller for the flat ones.\n\nThe fastest read is no JSON at all. The same value in its own text column next to the document took 18.1 ms on the medium table, against 311 ms through `doc->>'last'`. For the large documents, which live in TOAST, the column took 0.49 ms against 146 ms: the scan never had to touch the documents. On the small table, where nothing is compressed, the gain was smaller: 134 against 200 ms.\n\nLoading is where `jsonb` pays. `COPY` took 2.4 times as long for the small documents, 3,742 against 1,546 ms for a million rows, and 4.6 times as long for the medium documents with pglz, where `jsonb` was compressed and `json` was not. The smallest gap was 1.08 times, on the flat documents.\n\n## Does a GIN index help?\n\nOnly `jsonb` has one. `CREATE INDEX … USING gin (j)` on a `json` column fails with `data type json has no default operator class for access method \"gin\"`, and `json` has no `@>` operator either. What you can do is cast in the query, `doc::jsonb @> '{\"tag\":\"r042\"}'`, and that took 12.3 times as long as the same query on a `jsonb` column on the small table: 2,909 against 236 ms. On the medium and large tables it was 6.5 and 7.7 times.\n\nWith a GIN index on the `jsonb` column, PostgreSQL 17.11, compact documents, pglz:\n\n| Containment query | Matches | No index | `jsonb_ops` | `jsonb_path_ops` |\n| --- | --- | --- | --- | --- |\n| small: `{\"tag\":\"r042\"}` | 982 of 1,000,000 | 236.4 ms | 4.30 ms | 0.74 ms |\n| small: `{\"status\":\"active\"}` | 599,506 | 256.2 ms | 261.7 ms | 263.0 ms |\n| small: key value that does not exist | 0 | 232.5 ms | 0.07 ms | 0.05 ms |\n| medium: `{\"tag\":\"r042\"}` | 119 of 100,000 | 312.5 ms | 0.76 ms | 0.43 ms |\n| medium: `{\"status\":\"active\"}` | 59,917 | 313.8 ms | 205.9 ms | 203.3 ms |\n| medium: nested, country in the address | 8,371 | 331.2 ms | 34.6 ms | 33.1 ms |\n| large: one SKU inside an array of 165 items | 144 of 5,000 | 217.0 ms | 5.31 ms | 5.29 ms |\n\nFor the rare values the index answered in 0.4 to 5.3 ms instead of 217 to 313 ms, and for the nested query with 8,371 matches it was about ten times faster. For a value that six in ten rows have, it did not help on the small table: PostgreSQL 17 kept the sequential scan, and PostgreSQL 18 chose the index and took 261.7 and 242.0 ms, against 268.3 ms without it. On the medium table, where a row is bigger, the index brought that query from 313.8 to about 205 ms.\n\nThe index is not small. On the small table `jsonb_ops` came to 407.1 MB, larger than the 292.9 MB table it indexes; `jsonb_path_ops` to 299.2 MB. On the large documents `jsonb_ops` was 3.4 times the size of the table. `jsonb_path_ops` was smaller every time and about twice as fast to build, 13.2 against 26.1 s on the small table, and on these queries as fast or faster. It does not support the key-exists operator `?`, which we showed in our [hstore vs jsonb measurement](https://now-next.nl/en/insights/postgresql-hstore-vs-jsonb-measured/), so pick `jsonb_ops` only if you need that.\n\nPostgreSQL 18 can build a GIN index with parallel workers. With two, `jsonb_ops` on the small table took 16.0 s against 27.1 s without, and 7.5 against 15.3 s on the medium table; on the large table with 5,000 rows it did not help, and on 17 the setting made no difference. That is one run per variant. The indexes came out exactly the same size on both versions.\n\n## Is updating a key cheaper in jsonb?\n\n`json` has no function to change a key: `json_set` does not exist and `jsonb_set` does not accept `json`. You go through `jsonb` and back, which also rewrites your text in `jsonb`’s format. That took 1.8 times as long as `jsonb_set` on 50,000 small documents, 513.7 against 282.1 ms, 1.3 times on the medium documents and 1.7 times on the large ones, all with pglz. With lz4, where `jsonb_set` itself was faster on the compressed documents, the gap grew to 2.8 times for medium and 3.4 times for large.\n\nEither way, PostgreSQL writes the whole document again. Changing one status in a large document, about 6.9 KB compressed, wrote 7,947 bytes of WAL per row with pglz, after the pages were already in the WAL since the last checkpoint. Changing the same status in a separate column wrote 231 bytes, because the document in TOAST stayed where it was. For medium documents a separate column saved nothing: 1,386 against 1,382 bytes per row, because the compressed document lives in the row itself and is copied along with every update.\n\n## What does jsonb change in your data?\n\n`json` stores the text. `jsonb` stores what it parsed, and gives back its own rendering of it. On both versions, with identical output:\n\n| Input | `json` | `jsonb` |\n| --- | --- | --- |\n| `{\"a\":1,\"a\":2}` | kept as typed; `->>'a'` returns `2`, `json_object_keys` returns `a` twice | `{\"a\": 2}`: the last value wins |\n| `{\"zebra\":1,\"a\":2,\"mm\":3}` | kept as typed | `{\"a\": 2, \"mm\": 3, \"zebra\": 1}` |\n| `{ \"a\" : 1 }` | kept, 12 characters | `{\"a\": 1}`, 8 characters |\n| `1.10`, `1e2`, `1E-2`, `-0` | kept as typed | `1.10`, `100`, `0.01`, `0` |\n| `1e400` | kept | a number of 401 characters |\n| `1e200000` | accepted | `value overflows numeric format` |\n| `\"\\u0000\"` | accepted, but `->>` fails with `unsupported Unicode escape sequence` | rejected on input |\n| `\"\\ud83d\"`, an unpaired surrogate | accepted | rejected on input |\n\nCheck for duplicate keys before you migrate: `jsonb` silently keeps the last value, and `IS JSON WITH UNIQUE KEYS` finds them. Trailing zeros survive, so `1.10` stays `1.10`, but `[1.10]` and `[1.1]` are equal as `jsonb`. Numbers are stored as `numeric`, so `123456789012345678901234567890.123456789` came back digit for digit; that is the exact type we discuss for amounts in [money in PostgreSQL](https://now-next.nl/en/insights/money-in-postgresql-numeric-integer-or-money/). And `jsonb`’s output is not your input: it puts a space after every colon and comma, so the small documents came back as 224.4 bytes of text where 203.4 went in.\n\n`json` has no equality at all. `=`, `GROUP BY`, `DISTINCT`, `ORDER BY`, `UNION`, `IN`, `min()` and a primary key or unique constraint all failed, with errors such as `operator does not exist: json = json` and `could not identify an equality operator for type json`. With `jsonb`, `{\"a\":1}`, `{\"a\": 1}` and `{\"a\":1.0}` formed one group of three.\n\n## When would we still use json?\n\nWhen the exact text matters, such as a webhook payload you verify against a signature, or a document you store and return without looking inside. Compact `json` was also cheaper to load, and smaller on disk for small documents. For anything you query, filter, group, index or update, we would use `jsonb`, with `jsonb_path_ops` if you need a GIN index and not the `?` operator, and consider `lz4` for documents above 2 kB that you read often, after checking what it does to the size of yours: for two of our four shapes it took 25 to 45% more room. If one key in a large document changes often or is read in every query, give it its own column.\n\n## Reproduce the benchmark\n\nTwo files: [`setup.sql`](https://now-next.nl/files/json-vs-jsonb-benchmark/setup.sql) creates the measurement procedures, [`run.sh`](https://now-next.nl/files/json-vs-jsonb-benchmark/run.sh) generates the documents from a fixed seed, starts a container per version, runs every measurement and removes the container again. It needs Docker and Python 3 and about 30 GB of free disk; `SCALE=0.02 ./run.sh` runs a quick trial. On our machine a full run took about 20 minutes per version. The script writes every timing, size and query plan as CSV to a `results` folder next to itself, plus the full `psql` output of the behaviour checks in this article.\n\n## What we did not measure\n\nReturning whole documents to a client, where `json` hands back its text and `jsonb` has to render it. `jsonpath` queries and the SQL/JSON functions. B-tree expression indexes on a key. Documents larger than about 40 KB, concurrent writers, a cold cache and tuned compression. The size of `jsonb` with values we did not generate, such as long texts, floating-point numbers with many digits or deep nesting: our integers already behaved very differently from our strings. All timings are from one machine; read them as relative, not absolute, and differences under 10% as a tie.\n\n*Sources: the PostgreSQL 17 documentation on [JSON types](https://www.postgresql.org/docs/17/datatype-json.html) and on [TOAST](https://www.postgresql.org/docs/17/storage-toast.html); Alexander Korotkov, Oleg Bartunov and Teodor Sigaev, [JsQuery, slides from PGConf.Russia 2015](https://pgconf.ru/rmedia/2015c/korotkov.pdf), the “Jsonb vs Json” slide with the table sizes; [PostgreSQL JSON vs JSONB: 1M row benchmark](https://www.besthub.dev/articles/postgresql-json-vs-jsonb-1m-row-benchmark-shows-7x-query-speed-gap-827db964c168) on BestHub, by the dbaplus Community, read on 6 November 2026. All measurements are our own, on PostgreSQL 17.11 on 3 November 2026 and on PostgreSQL 18.6 on 5 and 6 November 2026, in throwaway containers; the BestHub generator we ran on PostgreSQL 17.11 on 6 November 2026, with a fixed seed and otherwise as printed.*\n","body_html":"<h1 id=\"json-vs-jsonb-in-postgresql-size-and-speed-measured\">json vs jsonb in PostgreSQL: size and speed, measured</h1>\n<p>json vs jsonb in PostgreSQL 17 and 18, measured on six document shapes: when jsonb is 23% smaller or 41% larger, read speed, GIN, and what it changes.</p>\n<p><a href=\"https://now-next.nl/en/about/\" rel=\"nofollow ugc noopener\">Chris van Eijk, Now-Next</a> ·\n9 November 2026\n· 10 min read</p>\n<p>Now-Next builds SaaS products and takes over existing ones. <a href=\"https://now-next.nl/en/services/\" rel=\"nofollow ugc noopener\">What we build →</a></p>\n<p>Whether <code>jsonb</code> takes more room than <code>json</code> depends on the JSON you put in, not on the type alone. In PostgreSQL 17.11 and 18.6, which stored every table byte for byte the same size, a million compact documents of about 200 bytes took 17.8% more room as <code>jsonb</code>, while the same documents pretty-printed took 3.6% less; across six document shapes, two input forms and two compression methods we measured everything from 22.6% smaller to 40.9% larger. Reading one key with <code>-&gt;&gt;</code> was 2.7 to 10.6 times faster from <code>jsonb</code> in every case we timed, and only <code>jsonb</code> can be compared, grouped or indexed for containment at all.</p>\n<p>Two numbers that show up when you search for this point in opposite directions. In the slides of a PGConf.Russia talk from 2015 by Alexander Korotkov, Oleg Bartunov and Teodor Sigaev, 1.25 million bookmarks take 1,374 MB as <code>jsonb</code> against 1,322 MB as <code>json</code>: “overhead is &lt; 4%”. A benchmark republished on BestHub in September 2026 reports about 888 MB against 1,200 MB for a million rows, 26% smaller. Korotkov’s 4% falls inside the range we measured. The 26% we could not reproduce: we ran the generator printed in that article for a million rows, with <code>json.dumps</code> called without arguments as it is there, which writes a space after every comma and colon, and <code>jsonb</code> came out 6.7% larger, 653.5 against 612.6 MB. In our own measurements four things decided which way it went: what the documents contain, whether the JSON contains whitespace, whether a document is large enough for PostgreSQL to compress it, and which compression method it uses.</p>\n<h2 id=\"json-vs-jsonb-at-a-glance\">json vs jsonb at a glance</h2>\n<p>PostgreSQL 17.11. Size is the whole table including TOAST, after <code>VACUUM</code>; the read is <code>sum(length(doc-&gt;&gt;&#39;first&#39;))</code> over the whole table, without an index:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Documents</th><th>Rows</th><th>Average input</th><th><code>jsonb</code> vs <code>json</code>, pglz (default)</th><th><code>jsonb</code> vs <code>json</code>, lz4</th><th>Read one key, <code>json</code> → <code>jsonb</code></th></tr></thead><tbody><tr><td>small, compact</td><td>1,000,000</td><td>203.4 bytes</td><td>+17.8%</td><td>+17.8%</td><td>1,379 → 204 ms</td></tr><tr><td>small, pretty-printed</td><td>1,000,000</td><td>248.4 bytes</td><td>−3.6%</td><td>−3.6%</td><td>1,498 → 207 ms</td></tr><tr><td>small with long keys, compact</td><td>1,000,000</td><td>423.4 bytes</td><td>+6.3%</td><td>+6.3%</td><td>not timed</td></tr><tr><td>medium, compact</td><td>100,000</td><td>1,517.9 bytes</td><td>−16.6%</td><td>−16.6%</td><td>850 → 310 ms</td></tr><tr><td>medium, pretty-printed</td><td>100,000</td><td>2,381.9 bytes</td><td>+16.6%</td><td>the same</td><td>1,275 → 313 ms</td></tr><tr><td>large, compact</td><td>5,000</td><td>20,532.0 bytes</td><td>+33.0%</td><td>+22.2%</td><td>541 → 146 ms</td></tr><tr><td>large, pretty-printed</td><td>5,000</td><td>28,829.0 bytes</td><td>the same</td><td>+0.1%</td><td>604 → 144 ms</td></tr><tr><td>flat, 780 random strings, compact</td><td>5,000</td><td>21,129.0 bytes</td><td>−22.6%</td><td>−10.4%</td><td>430 → 149 ms</td></tr><tr><td>flat, pretty-printed</td><td>5,000</td><td>24,266.0 bytes</td><td>−5.5%</td><td>−10.4%</td><td>602 → 149 ms</td></tr><tr><td>array of 3,500 integers, compact</td><td>5,000</td><td>20,692.3 bytes</td><td>+3.2%</td><td>+40.9%</td><td>791 → 249 ms</td></tr><tr><td>array of integers, pretty-printed</td><td>5,000</td><td>38,216.3 bytes</td><td>+1.9%</td><td>+20.0%</td><td>868 → 249 ms</td></tr></tbody></table></div>\n<p>The read times are from the pglz tables. On PostgreSQL 18.6 they were within 6% of these, except the small <code>jsonb</code> tables, which read 6 to 15% faster; <code>jsonb</code> was the faster type in every row on both versions.</p>\n<h2 id=\"the-setup\">The setup</h2>\n<p>PostgreSQL 17.11 and 18.6 in throwaway containers from the official images, on one machine with an 8-core Ryzen 7 3700X and 62 GiB of memory. <code>shared_buffers</code> 2 GB, so every table we queried was read from shared memory; autovacuum, JIT and parallel query off, data checksums on. Six document shapes, generated from a fixed seed:</p>\n<ul><li><strong>small</strong>: eleven flat keys of short strings, numbers and a boolean, like <code>{&quot;first&quot;:&quot;e6a14425&quot;,&quot;id&quot;:1,&quot;status&quot;:&quot;closed&quot;,&quot;tag&quot;:&quot;r520&quot;,&quot;plan&quot;:&quot;free&quot;,&quot;country&quot;:&quot;NO&quot;,&quot;score&quot;:28.78,&quot;active&quot;:true,…}</code></li><li><strong>small with long keys</strong>: the same values under keys like <code>subscription_lifecycle_status</code></li><li><strong>medium</strong>: a nested order with a customer, an address, seven order lines and five events</li><li><strong>large</strong>: a customer and 165 line items</li><li><strong>flat</strong>: 780 keys with a random 16-character string each, which compresses badly</li><li><strong>array of integers</strong>: 3,500 whole numbers between 0 and 99,999</li></ul>\n<p>Each shape was written twice from the same values: compact, and pretty-printed with an indent of two, as <code>JSON.stringify(x, null, 2)</code> writes it. Each went into four tables, loaded with <code>COPY</code>: <code>json</code> and <code>jsonb</code>, each with <code>default_toast_compression</code> <code>pglz</code> (the default) and <code>lz4</code>. Timings were taken inside the server: for queries the median of five runs after one untimed warm-up, for loads, index builds and updates the median of three. The scripts are linked at the end.</p>\n<h2 id=\"is-jsonb-bigger-than-json\">Is jsonb bigger than json?</h2>\n<p>Before compression, always bigger than compact JSON; on disk, it depends. The type stores a parsed document: a header for every key and value, keys sorted, numbers as <code>numeric</code>. To see that layer on its own, we also measured the size of each document as an uncompressed value, with <code>pg_column_size(doc::json)</code> and <code>pg_column_size(doc::jsonb)</code> over all rows, on both versions:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Documents</th><th><code>json</code>, compact</th><th><code>json</code>, pretty-printed</th><th><code>jsonb</code>, either input</th><th><code>jsonb</code> vs compact</th><th><code>jsonb</code> vs pretty-printed</th></tr></thead><tbody><tr><td>small</td><td>207.4 bytes</td><td>252.4 bytes</td><td>245.9 bytes</td><td>+18.5%</td><td>−2.6%</td></tr><tr><td>small with long keys</td><td>427.4 bytes</td><td>—</td><td>465.8 bytes</td><td>+9.0%</td><td>—</td></tr><tr><td>medium</td><td>1,521.9 bytes</td><td>2,385.9 bytes</td><td>2,071.9 bytes</td><td>+36.1%</td><td>−13.2%</td></tr><tr><td>large</td><td>20,536.0 bytes</td><td>28,833.0 bytes</td><td>26,476.1 bytes</td><td>+28.9%</td><td>−8.2%</td></tr><tr><td>flat</td><td>21,133.0 bytes</td><td>24,270.0 bytes</td><td>22,704.0 bytes</td><td>+7.4%</td><td>−6.5%</td></tr><tr><td>array of integers</td><td>20,696.3 bytes</td><td>38,220.3 bytes</td><td>54,701.6 bytes</td><td>+164.3%</td><td>+43.1%</td></tr></tbody></table></div>\n<p>Three things follow from that table and from the stored sizes above.</p>\n<p><strong>The overhead is per key, not per byte.</strong> The small documents grew by 38.5 bytes in <code>jsonb</code>, the same documents with long keys by 38.4: 18.5% and 9.0%. Our small documents were not compressed, so the overhead carried over to disk: 17.8% and 6.3% larger tables, a little less than per value because every row also has a header of its own.</p>\n<p><strong>Whitespace is gone in <code>jsonb</code>, and that can pay for the headers.</strong> <code>json</code> keeps your text as it arrived, indentation and all; <code>jsonb</code> came out the same size from both inputs, and before compression smaller than pretty-printed <code>json</code> in every shape except the integer array. Integers are where <code>jsonb</code> grows most: 3,500 of them took 54.7 KB against 20.7 KB as compact text.</p>\n<p><strong>Compression reorders everything.</strong> PostgreSQL tries to compress a value once a row gets larger than about 2 kB, according to the documentation on TOAST. The compact medium document, 1,521.9 bytes as <code>json</code>, stayed under that and was stored uncompressed in all 100,000 rows. The same document as <code>jsonb</code>, 2,071.9 bytes, went over, and was compressed in all 100,000 rows, to 1,149.7 bytes with pglz. That is how a type that is 36% larger before compression ends up 16.6% smaller on disk. On the flat documents pglz left the compact <code>json</code> text uncompressed in all 5,000 rows, but did compress the <code>jsonb</code> form. Once both sides were compressed, <code>jsonb</code> was as large or larger in ten of the thirteen cases, up to 33.0% for the large compact documents with pglz and 22.2% with lz4; only the flat documents with random strings were 5.5 to 10.4% smaller as <code>jsonb</code>. Whitespace compresses well, so for pretty-printed medium documents the advantage turned around: 13.2% smaller before compression, 16.6% larger after pglz. And the method matters per shape: for the integer array, lz4 made <code>jsonb</code> 40.9% larger, pglz 3.2%.</p>\n<p>Bytes per medium document, 100,000 orders, before compression and as stored with pglz: PostgreSQL 17.11 and 18.6</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Type, input and state</th><th>Bytes per document</th></tr></thead><tbody><tr><td><code>json</code>, compact, before compression</td><td>1,521.9</td></tr><tr><td><code>json</code>, compact, stored: not compressed</td><td>1,521.9</td></tr><tr><td><code>json</code>, pretty-printed, before compression</td><td>2,385.9</td></tr><tr><td><code>json</code>, pretty-printed, stored</td><td>1,018.7</td></tr><tr><td><code>jsonb</code>, either input, before compression</td><td>2,071.9</td></tr><tr><td><code>jsonb</code>, either input, stored</td><td>1,149.7</td></tr></tbody></table></div>\n<p>Bar length is linear, against the largest value. Grey is the value before compression, violet the average stored value in the table, both measured with <code>pg_column_size</code>. Only compact <code>json</code> stays under the threshold of about 2 kB and is stored as typed; the two larger forms get compressed and end up smaller.</p>\n<p>The result is a ranking that turns the uncompressed one upside down. On disk, pretty-printed <code>json</code> was the smallest of the three, 117.5 MB for the table, then <code>jsonb</code> with 136.9 to 137.0 MB, and compact <code>json</code>, the smallest before compression, was the largest with 164.2 MB.</p>\n<p>So for a quick estimate: small documents are 6 to 18% larger as <code>jsonb</code> if your application sends compact JSON, and slightly smaller if it sends pretty-printed JSON. Above about 2 kB, measure your own documents.</p>\n<h2 id=\"is-jsonb-faster-to-read\">Is jsonb faster to read?</h2>\n<p>Yes, in every case we timed. Extracting one key with <code>-&gt;&gt;</code> from the whole table, without an index, was 2.7 to 10.5 times faster from <code>jsonb</code> on PostgreSQL 17.11 and 2.8 to 10.6 times on 18.6. <code>json</code> has to parse the text again on every read. It made no difference whether we asked for the key written first or the one written last: 1,379 against 1,397 ms for <code>json</code> on the small table, 204 against 200 ms for <code>jsonb</code>.</p>\n<p>For documents that PostgreSQL compresses, the compression method mattered as much as the type. Reading one key from the medium <code>jsonb</code> documents took 310 ms with pglz and 96 ms with lz4; from the flat ones 149 against 42 ms. Before <code>-&gt;&gt;</code> can look inside a compressed document, PostgreSQL has to decompress it, and lz4 was the faster of the two at that. It is not free on disk: the <code>jsonb</code> tables were 24.8% larger with lz4 than with pglz for the large documents and 45.1% for the integer array, the same size for the medium ones and 5.3% smaller for the flat ones.</p>\n<p>The fastest read is no JSON at all. The same value in its own text column next to the document took 18.1 ms on the medium table, against 311 ms through <code>doc-&gt;&gt;&#39;last&#39;</code>. For the large documents, which live in TOAST, the column took 0.49 ms against 146 ms: the scan never had to touch the documents. On the small table, where nothing is compressed, the gain was smaller: 134 against 200 ms.</p>\n<p>Loading is where <code>jsonb</code> pays. <code>COPY</code> took 2.4 times as long for the small documents, 3,742 against 1,546 ms for a million rows, and 4.6 times as long for the medium documents with pglz, where <code>jsonb</code> was compressed and <code>json</code> was not. The smallest gap was 1.08 times, on the flat documents.</p>\n<h2 id=\"does-a-gin-index-help\">Does a GIN index help?</h2>\n<p>Only <code>jsonb</code> has one. <code>CREATE INDEX … USING gin (j)</code> on a <code>json</code> column fails with <code>data type json has no default operator class for access method &quot;gin&quot;</code>, and <code>json</code> has no <code>@&gt;</code> operator either. What you can do is cast in the query, <code>doc::jsonb @&gt; &#39;{&quot;tag&quot;:&quot;r042&quot;}&#39;</code>, and that took 12.3 times as long as the same query on a <code>jsonb</code> column on the small table: 2,909 against 236 ms. On the medium and large tables it was 6.5 and 7.7 times.</p>\n<p>With a GIN index on the <code>jsonb</code> column, PostgreSQL 17.11, compact documents, pglz:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Containment query</th><th>Matches</th><th>No index</th><th><code>jsonb_ops</code></th><th><code>jsonb_path_ops</code></th></tr></thead><tbody><tr><td>small: <code>{&quot;tag&quot;:&quot;r042&quot;}</code></td><td>982 of 1,000,000</td><td>236.4 ms</td><td>4.30 ms</td><td>0.74 ms</td></tr><tr><td>small: <code>{&quot;status&quot;:&quot;active&quot;}</code></td><td>599,506</td><td>256.2 ms</td><td>261.7 ms</td><td>263.0 ms</td></tr><tr><td>small: key value that does not exist</td><td>0</td><td>232.5 ms</td><td>0.07 ms</td><td>0.05 ms</td></tr><tr><td>medium: <code>{&quot;tag&quot;:&quot;r042&quot;}</code></td><td>119 of 100,000</td><td>312.5 ms</td><td>0.76 ms</td><td>0.43 ms</td></tr><tr><td>medium: <code>{&quot;status&quot;:&quot;active&quot;}</code></td><td>59,917</td><td>313.8 ms</td><td>205.9 ms</td><td>203.3 ms</td></tr><tr><td>medium: nested, country in the address</td><td>8,371</td><td>331.2 ms</td><td>34.6 ms</td><td>33.1 ms</td></tr><tr><td>large: one SKU inside an array of 165 items</td><td>144 of 5,000</td><td>217.0 ms</td><td>5.31 ms</td><td>5.29 ms</td></tr></tbody></table></div>\n<p>For the rare values the index answered in 0.4 to 5.3 ms instead of 217 to 313 ms, and for the nested query with 8,371 matches it was about ten times faster. For a value that six in ten rows have, it did not help on the small table: PostgreSQL 17 kept the sequential scan, and PostgreSQL 18 chose the index and took 261.7 and 242.0 ms, against 268.3 ms without it. On the medium table, where a row is bigger, the index brought that query from 313.8 to about 205 ms.</p>\n<p>The index is not small. On the small table <code>jsonb_ops</code> came to 407.1 MB, larger than the 292.9 MB table it indexes; <code>jsonb_path_ops</code> to 299.2 MB. On the large documents <code>jsonb_ops</code> was 3.4 times the size of the table. <code>jsonb_path_ops</code> was smaller every time and about twice as fast to build, 13.2 against 26.1 s on the small table, and on these queries as fast or faster. It does not support the key-exists operator <code>?</code>, which we showed in our <a href=\"https://now-next.nl/en/insights/postgresql-hstore-vs-jsonb-measured/\" rel=\"nofollow ugc noopener\">hstore vs jsonb measurement</a>, so pick <code>jsonb_ops</code> only if you need that.</p>\n<p>PostgreSQL 18 can build a GIN index with parallel workers. With two, <code>jsonb_ops</code> on the small table took 16.0 s against 27.1 s without, and 7.5 against 15.3 s on the medium table; on the large table with 5,000 rows it did not help, and on 17 the setting made no difference. That is one run per variant. The indexes came out exactly the same size on both versions.</p>\n<h2 id=\"is-updating-a-key-cheaper-in-jsonb\">Is updating a key cheaper in jsonb?</h2>\n<p><code>json</code> has no function to change a key: <code>json_set</code> does not exist and <code>jsonb_set</code> does not accept <code>json</code>. You go through <code>jsonb</code> and back, which also rewrites your text in <code>jsonb</code>’s format. That took 1.8 times as long as <code>jsonb_set</code> on 50,000 small documents, 513.7 against 282.1 ms, 1.3 times on the medium documents and 1.7 times on the large ones, all with pglz. With lz4, where <code>jsonb_set</code> itself was faster on the compressed documents, the gap grew to 2.8 times for medium and 3.4 times for large.</p>\n<p>Either way, PostgreSQL writes the whole document again. Changing one status in a large document, about 6.9 KB compressed, wrote 7,947 bytes of WAL per row with pglz, after the pages were already in the WAL since the last checkpoint. Changing the same status in a separate column wrote 231 bytes, because the document in TOAST stayed where it was. For medium documents a separate column saved nothing: 1,386 against 1,382 bytes per row, because the compressed document lives in the row itself and is copied along with every update.</p>\n<h2 id=\"what-does-jsonb-change-in-your-data\">What does jsonb change in your data?</h2>\n<p><code>json</code> stores the text. <code>jsonb</code> stores what it parsed, and gives back its own rendering of it. On both versions, with identical output:</p>\n<div class=\"table-wrap\"><table><thead><tr><th>Input</th><th><code>json</code></th><th><code>jsonb</code></th></tr></thead><tbody><tr><td><code>{&quot;a&quot;:1,&quot;a&quot;:2}</code></td><td>kept as typed; <code>-&gt;&gt;&#39;a&#39;</code> returns <code>2</code>, <code>json_object_keys</code> returns <code>a</code> twice</td><td><code>{&quot;a&quot;: 2}</code>: the last value wins</td></tr><tr><td><code>{&quot;zebra&quot;:1,&quot;a&quot;:2,&quot;mm&quot;:3}</code></td><td>kept as typed</td><td><code>{&quot;a&quot;: 2, &quot;mm&quot;: 3, &quot;zebra&quot;: 1}</code></td></tr><tr><td><code>{ &quot;a&quot; : 1 }</code></td><td>kept, 12 characters</td><td><code>{&quot;a&quot;: 1}</code>, 8 characters</td></tr><tr><td><code>1.10</code>, <code>1e2</code>, <code>1E-2</code>, <code>-0</code></td><td>kept as typed</td><td><code>1.10</code>, <code>100</code>, <code>0.01</code>, <code>0</code></td></tr><tr><td><code>1e400</code></td><td>kept</td><td>a number of 401 characters</td></tr><tr><td><code>1e200000</code></td><td>accepted</td><td><code>value overflows numeric format</code></td></tr><tr><td><code>&quot;\\u0000&quot;</code></td><td>accepted, but <code>-&gt;&gt;</code> fails with <code>unsupported Unicode escape sequence</code></td><td>rejected on input</td></tr><tr><td><code>&quot;\\ud83d&quot;</code>, an unpaired surrogate</td><td>accepted</td><td>rejected on input</td></tr></tbody></table></div>\n<p>Check for duplicate keys before you migrate: <code>jsonb</code> silently keeps the last value, and <code>IS JSON WITH UNIQUE KEYS</code> finds them. Trailing zeros survive, so <code>1.10</code> stays <code>1.10</code>, but <code>[1.10]</code> and <code>[1.1]</code> are equal as <code>jsonb</code>. Numbers are stored as <code>numeric</code>, so <code>123456789012345678901234567890.123456789</code> came back digit for digit; that is the exact type we discuss for amounts in <a href=\"https://now-next.nl/en/insights/money-in-postgresql-numeric-integer-or-money/\" rel=\"nofollow ugc noopener\">money in PostgreSQL</a>. And <code>jsonb</code>’s output is not your input: it puts a space after every colon and comma, so the small documents came back as 224.4 bytes of text where 203.4 went in.</p>\n<p><code>json</code> has no equality at all. <code>=</code>, <code>GROUP BY</code>, <code>DISTINCT</code>, <code>ORDER BY</code>, <code>UNION</code>, <code>IN</code>, <code>min()</code> and a primary key or unique constraint all failed, with errors such as <code>operator does not exist: json = json</code> and <code>could not identify an equality operator for type json</code>. With <code>jsonb</code>, <code>{&quot;a&quot;:1}</code>, <code>{&quot;a&quot;: 1}</code> and <code>{&quot;a&quot;:1.0}</code> formed one group of three.</p>\n<h2 id=\"when-would-we-still-use-json\">When would we still use json?</h2>\n<p>When the exact text matters, such as a webhook payload you verify against a signature, or a document you store and return without looking inside. Compact <code>json</code> was also cheaper to load, and smaller on disk for small documents. For anything you query, filter, group, index or update, we would use <code>jsonb</code>, with <code>jsonb_path_ops</code> if you need a GIN index and not the <code>?</code> operator, and consider <code>lz4</code> for documents above 2 kB that you read often, after checking what it does to the size of yours: for two of our four shapes it took 25 to 45% more room. If one key in a large document changes often or is read in every query, give it its own column.</p>\n<h2 id=\"reproduce-the-benchmark\">Reproduce the benchmark</h2>\n<p>Two files: <a href=\"https://now-next.nl/files/json-vs-jsonb-benchmark/setup.sql\" rel=\"nofollow ugc noopener\"><code>setup.sql</code></a> creates the measurement procedures, <a href=\"https://now-next.nl/files/json-vs-jsonb-benchmark/run.sh\" rel=\"nofollow ugc noopener\"><code>run.sh</code></a> generates the documents from a fixed seed, starts a container per version, runs every measurement and removes the container again. It needs Docker and Python 3 and about 30 GB of free disk; <code>SCALE=0.02 ./run.sh</code> runs a quick trial. On our machine a full run took about 20 minutes per version. The script writes every timing, size and query plan as CSV to a <code>results</code> folder next to itself, plus the full <code>psql</code> output of the behaviour checks in this article.</p>\n<h2 id=\"what-we-did-not-measure\">What we did not measure</h2>\n<p>Returning whole documents to a client, where <code>json</code> hands back its text and <code>jsonb</code> has to render it. <code>jsonpath</code> queries and the SQL/JSON functions. B-tree expression indexes on a key. Documents larger than about 40 KB, concurrent writers, a cold cache and tuned compression. The size of <code>jsonb</code> with values we did not generate, such as long texts, floating-point numbers with many digits or deep nesting: our integers already behaved very differently from our strings. All timings are from one machine; read them as relative, not absolute, and differences under 10% as a tie.</p>\n<p><em>Sources: the PostgreSQL 17 documentation on <a href=\"https://www.postgresql.org/docs/17/datatype-json.html\" rel=\"nofollow ugc noopener\">JSON types</a> and on <a href=\"https://www.postgresql.org/docs/17/storage-toast.html\" rel=\"nofollow ugc noopener\">TOAST</a>; Alexander Korotkov, Oleg Bartunov and Teodor Sigaev, <a href=\"https://pgconf.ru/rmedia/2015c/korotkov.pdf\" rel=\"nofollow ugc noopener\">JsQuery, slides from PGConf.Russia 2015</a>, the “Jsonb vs Json” slide with the table sizes; <a href=\"https://www.besthub.dev/articles/postgresql-json-vs-jsonb-1m-row-benchmark-shows-7x-query-speed-gap-827db964c168\" rel=\"nofollow ugc noopener\">PostgreSQL JSON vs JSONB: 1M row benchmark</a> on BestHub, by the dbaplus Community, read on 6 November 2026. All measurements are our own, on PostgreSQL 17.11 on 3 November 2026 and on PostgreSQL 18.6 on 5 and 6 November 2026, in throwaway containers; the BestHub generator we ran on PostgreSQL 17.11 on 6 November 2026, with a fixed seed and otherwise as printed.</em></p>","headings":[{"level":1,"text":"json vs jsonb in PostgreSQL: size and speed, measured","id":"json-vs-jsonb-in-postgresql-size-and-speed-measured"},{"level":2,"text":"json vs jsonb at a glance","id":"json-vs-jsonb-at-a-glance"},{"level":2,"text":"The setup","id":"the-setup"},{"level":2,"text":"Is jsonb bigger than json?","id":"is-jsonb-bigger-than-json"},{"level":2,"text":"Is jsonb faster to read?","id":"is-jsonb-faster-to-read"},{"level":2,"text":"Does a GIN index help?","id":"does-a-gin-index-help"},{"level":2,"text":"Is updating a key cheaper in jsonb?","id":"is-updating-a-key-cheaper-in-jsonb"},{"level":2,"text":"What does jsonb change in your data?","id":"what-does-jsonb-change-in-your-data"},{"level":2,"text":"When would we still use json?","id":"when-would-we-still-use-json"},{"level":2,"text":"Reproduce the benchmark","id":"reproduce-the-benchmark"},{"level":2,"text":"What we did not measure","id":"what-we-did-not-measure"}]}}