

The json type has its use cases, but it's mostly there for backward compatibility and specialized scenarios. So which one should we choose? Based on recommendations in their documentation, jsonb is the preferred data type for storing JSON. Postgres has two data types for this purpose. PostgreSQL JSON Data TypesĪs I mentioned previously Postgres has built-in support for JSON so we won't be storing the data as raw text. Finally, Postgres has built-in support for querying and processing JSON data natively. Since Postgres is also a relational database you're able to integrate relational and non-relational data seamlessly, providing greater flexibility to users/applications consuming the data. Why go with Postgres? Maybe your team or company is invested in Postgres and doesn't want the overhead of another database provider to use and manage, then Postgres is a great option. There are so many great document database options like MongoDB, CouchDB, Azure CosmosDB, Amazon DocumentDB, and many more (most public cloud services will have an offering). If you're thinking about storing JSON, your data model is probably unstructured and does not fit well into the relational model with consistent columns, relationships, etc. I think you're right in questioning the idea, but there are some situations where it can make sense. So you may be wondering why it's a good idea to store JSON data in a relational database in the first place. If you are on a different version and something mentioned doesn't work as expected, check the docs to verify that what is mentioned in this post exists in the version you're on.


The content in this post is directed at the functionality of PostgreSQL 13. Note: If you'd like to see the updated syntax for JSON support in PostgreSQL 14 checkout the post here! Let's take a look at how we can store and query this data in PostgreSQL. Home Posts About Querying JSON Data in PostgreSQL Storing JSON provides flexibility, but can add complexity.
