SQLSTATE 22032 ERROR Class 22: Data Exception

invalid_json_text invalid JSON text — 22032

PostgreSQL error “invalid JSON text — 22032” (SQLSTATE 22032): what it means, common causes, and how to fix it.

PG 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A string being cast to json/jsonb was not valid JSON. PostgreSQL raises SQLSTATE 22032 (invalid_json_text).

  • The text doesn’t parse as JSON.
  • Common with single quotes, trailing commas, or unquoted keys.
  • A DETAIL line points to the parse problem.

What the server log shows

ERROR:  invalid input syntax for type json
DETAIL:  Token "'" is invalid.
CONTEXT:  JSON data, line 1: {'name'...

Why PostgreSQL raises this — what the manual says

Section 8.14 JSON Types:

“JSON data types are for storing JSON (JavaScript Object Notation) data, as specified in RFC 7159.”

JSON/JSONB input is parsed against the JSON grammar. Text that violates it (single quotes, unquoted keys, trailing commas, bad tokens) can’t be parsed, so PostgreSQL reports 22032 with a DETAIL.

Common causes

  • Single quotes instead of double quotes for strings/keys.
  • Trailing commas or unquoted object keys.
  • Truncated or concatenated JSON.

How to fix it

  1. Produce strict JSON (double quotes, no trailing commas).
  2. Validate/serialize JSON with a proper library before inserting.
  3. Read the DETAIL/CONTEXT to locate the offending token.

Related & next steps

Reference: PostgreSQL 18 Section 8.14 “JSON Types”.

Was this helpful?