invalid JSON text

SQLSTATE 22032 condition invalid_json_text class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 11 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

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

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

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”.