🐘 PostgreSQL Intermediate

How does JSONB differ from JSON in PostgreSQL?

Why Interviewers Ask This

This question targets practical, hands-on experience with PostgreSQL. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

PostgreSQL supports two JSON storage types. JSON stores JSON as text, preserving the original format including whitespace and duplicate keys — it validates JSON syntax but doesn't parse deeply. JSONB stores JSON in a decomposed binary format — it parses and validates fully, removes whitespace, removes duplicate keys (last value wins), and reorders keys. Key advantages of JSONB: supports indexing (GIN indexes), has more operators, and is much faster for querying/filtering. Query operators: -> (get JSON object), ->> (get as text), #> (path access), @> (contains), <@ (contained by), ? (key exists). Always prefer JSONB over JSON unless you specifically need to preserve insertion order or duplicate keys.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last PostgreSQL project, I used this when...' immediately makes your answer more credible and memorable.