top of page

Difference between json and jsonb in PostgreSQL

Writer: Chandan Singh Rajpurohit
Chandan Singh Rajpurohit
Jan 21, 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


  1. want to perform a lot of INSERT operations.

  2. no complex queries are expected on JSON data.

  3. you want to preserve the original JSON data indentation and format


When to use jsonb data type


  1. want to store configuration data.

  2. 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.


Recent Posts

See All
Babel 101: Writing Future JavaScript, Today

If you’ve spent any time in the JavaScript ecosystem, you’ve likely heard the name Babel come up again and again. It’s one of those tools that quietly powers a huge portion of the modern web, yet many

 
 
Difference between json.dumps() and json.loads()

JSON is important for many backend devs. But sometimes playing with it can be confusing. Being a backend dev or full stack dev you might have written APIs for your Web or Mobile application and I’m su

 
 
How to work with DataFrame in Python?

Python language has vast application. Data analysis and manipulation is one of many application. We can work on data using Pandas library in Python for generating data analytics and manipulating data

 
 
bottom of page