JSON Best Practices
Use JSON for flexible attributes, not for relationships that should be normalized. Index frequently queried paths with generated columns. Avoid storing large blobs in JSON columns.
Use JSON for flexible attributes, not for relationships that should be normalized. Index frequently queried paths with generated columns. Avoid storing large blobs in JSON columns.
-- Good use: product attributes (variable per category)
-- Bad use: storing related records as JSON arrays
-- (should be a separate table with FK)
-- Anti-pattern: user.roles = ["admin","editor"]
-- Better: user_roles table with user_id FK
-- Anti-pattern: JSON for reporting (no aggregation)
-- Better: materialized/generated columns for reported fields
Ask: "Would I ever need to JOIN or GROUP BY on this field?" If yes, use a regular column.