Skip to content
Sarj Code Standards

prefer-jsonb

JSON column type or table-DDL cast — use JSONB.

Why

JSONB supports indexing and containment operators and avoids reparsing the stored document on every read.

Fix

Declare JSONB columns and use jsonb casts for JSON document values.

Examples

Before — flagged An ALTER USING conversion still declares a plain JSON type
supabase/migrations/001_boundary.sql
ALTER TABLE document
ALTER COLUMN metadata TYPE json USING metadata::json;
After — preferred The target type and conversion both use JSONB
supabase/migrations/001_boundary.sql
ALTER TABLE document
ALTER COLUMN metadata TYPE jsonb USING metadata::jsonb;
Before — flagged Plain JSON column
supabase/migrations/001_documents.sql
CREATE TABLE document (metadata JSON NOT NULL);
After — preferred Indexable JSONB column
supabase/migrations/001_documents.sql
CREATE TABLE document (metadata JSONB NOT NULL DEFAULT '{}'::jsonb);