22032ERRORTier 2 — Caution✅ HIGH confidenceinvalid JSON text
What this means
SQLSTATE 22032 is raised when a string passed to a JSON or JSONB function or cast is not valid JSON text. The input must be well-formed JSON.
Why it happens
- 1Casting or parsing a string that is not valid JSON to JSON or JSONB type
- 2Single-quoted strings instead of double-quoted JSON strings
- 3Trailing commas, missing commas, or other JSON syntax violations
How to reproduce
Casting an invalid JSON string to JSONB.
SELECT '{key: value}'::jsonb; -- unquoted key is invalid JSONFix 1: Use valid JSON syntax with double-quoted keys and string values
When constructing JSON strings in SQL or application code.
SELECT '{"key": "value"}'::jsonb;Why this works
JSON requires double-quoted keys and string values, no trailing commas, and proper nesting.
Fix 2: Use jsonb_build_object() to construct JSON safely in SQL
When building JSON from SQL expressions.
SELECT jsonb_build_object('key', 'value', 'count', 42);Why this works
jsonb_build_object() constructs valid JSONB from SQL arguments without requiring manual JSON string construction.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 22 — Data Exception
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE for JSON parse errors. Stable across all Postgres versions that support JSON.
See also
🔗 Related errors
📄 Reference pages