JSON vs JSONB Postgresql
Aug 17
I am reading about differences between JSON and JSONB datatypes on PostgreSql documentation https://www.postgresql.org/docs/13/datatype-json.html.
There is this line
The json data type stores an exact copy of the input text, which processing functions must reparse on each execution; while jsonb data is stored in a decomposed binary format that makes it slightly slower to input due to added conversion overhead, but significantly faster to process, since no reparsing is needed
I am not able to understand what is the difference between storing as text and storing as binary format is, the string itself will be stored as as sequence of 0's and 1's.
Can somebody please clarify? Also, will there be a size difference between them?
1 answer
Accepted answer · original discussion
Aug 17
json is essentially stored as text, which needs to be parsed every time you operate on it. This means it does preserve whitespace formatting and allows peculiarities such as duplicate property keys in objects.
jsonb is an optimised binary format that represents the tree structure of nested arrays and objects, which is possibly smaller (idk) slightly larger to store but faster to access and operate on.
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
Aug 17
jsonb"