I would implement this as a constraint in the database. Then your application code doesn’t have to do anything. For example:
CREATE TABLE products (
my_json jsonb CONSTRAINT max_jsonb_size CHECK (pg_column_size(my_json) <= 1024)
);
I would implement this as a constraint in the database. Then your application code doesn’t have to do anything. For example:
CREATE TABLE products (
my_json jsonb CONSTRAINT max_jsonb_size CHECK (pg_column_size(my_json) <= 1024)
);