JSON vs TEXT
JSON columns validate structure, enable path extraction without full parsing, and support generated column indexes. TEXT stores JSON as a string with no built-in query support.
JSON columns validate structure, enable path extraction without full parsing, and support generated column indexes. TEXT stores JSON as a string with no built-in query support.
-- TEXT: no validation, no path queries
CREATE TABLE log1 (data TEXT);
INSERT INTO log1 VALUES ('not valid json'); -- works!
-- JSON: validated at insert
CREATE TABLE log2 (data JSON);
INSERT INTO log2 VALUES ('not valid json'); -- ERROR
Always use the JSON type for JSON data — TEXT is only for legacy compatibility.