top of page

Difference between json and jsonb in PostgreSQL

  • Writer: Chandan Rajpurohit
    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


  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.


Thank you for reading this article, I appreciate it. If you have any questions, feel free to leave a comment.


Recent Posts

See All
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

 
 
 

Comments


Made with ❤️ by Chandan Rajpurohit

© 2025 by CR. 

bottom of page