JSON stores data as plain text, which means it keeps the original formatting. JSONB stores data in a binary format, which allows faster processing and indexing.
SELECT json_col, jsonb_col FROM test_table;
JSON preserves duplicate keys as text, so it returns both. JSONB removes duplicates and keeps the last key-value pair.
JSONB supports GIN indexes which allow efficient searching inside the JSON structure. JSON does not support GIN indexing.
SELECT * FROM test_table WHERE json_col @> '{"key": "value"}';
The '@>' operator is supported for JSONB but not for JSON type, so using it on a JSON column causes an operator does not exist error.
JSON preserves the exact input text including whitespace and key order, which JSONB does not. This is useful when the original formatting matters.
