Difference between json and jsonb in PostgreSQL
- Chandan Rajpurohit
- Jan 20, 2024
- 1 min read
PostgreSQL allows to store JSON data in json and jsonb datatype. Let’s understand the difference between json and jsonb.
json | jsonb |
json datatype was first introduced with Postgres 9.2. | jsonb datatype was introduced in Postgres 9.4. |
json data type stores an exact copy of the input text. | jsonb stores data in a decomposed binay format. |
json does not support indexing | jsonb supports indexing [GIN (Generalized Inverted Index)] |
When to use json data type
want to perform a lot of INSERT operations.
no complex queries are expected on JSON data.
you want to preserve the original JSON data indentation and format
When to use jsonb data type
want to store configuration data.
data is highly nested data (the structure is expected to change over time).
In general, jsonb is faster than json while accessing data but can be a bit slow while insertion.
Additionally, for someone working in Django. Django ORM JSONField sets the datatype to jsonb by default in PostgreSQL.
Thank you for reading this article, I appreciate it. If you have any questions, feel free to leave a comment.
Comments