JSON
Use jsonb — faster and indexable
jsonbvariable (binary)Recommended
Flexible schema data, API responses, user preferences, feature flags.
Range
any valid JSON
Performance
Supports GIN indexes. Faster reads than json. Slightly slower writes.
Comparison
jsonb vs json: jsonb stores binary, supports indexing and containment operators (@>, ?). json stores raw text, preserves key order and duplicates. Use jsonb in 99% of cases.
SQL Example
CREATE TABLE user_settings (
user_id bigint PRIMARY KEY,
preferences jsonb NOT NULL DEFAULT '{}'
);
CREATE INDEX ON user_settings USING gin (preferences);