How to Fix Postgres Error 22035 No SQL Json Item

Published
Length
3 min read

Luis Felipe Dias

All posts

The postgres error 22035 no sql json item happens when a query searches for a JSON element that does not exist. You fix it by relaxing strict JSON path checks or adding fallback values in your query. Database teams often see this failure when an app updates its payload shape. Strict path queries expect every record to hold the exact same keys. When one row lacks that key, the database stops the query and returns an error. What causes postgres error 22035 no sql json item In PostgreSQL, the o

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

The postgres error 22035 no sql json item happens when a query searches for a JSON element that does not exist. You fix it by relaxing strict JSON path checks or adding fallback values in your query.

Database teams often see this failure when an app updates its payload shape. Strict path queries expect every record to hold the exact same keys. When one row lacks that key, the database stops the query and returns an error.

What causes postgres error 22035 no sql json item

In PostgreSQL, the official SQLSTATE code 22035 maps to the no_sql_json_item condition. The database engine tracks this under the internal macro ERRCODE_NO_SQL_JSON_ITEM. It belongs to the data exception class of database errors.

This error triggers when a JSON path expression runs in strict mode. Strict mode tells the engine that the structural path must match a real item. If a document lacks the target key or array index, the engine halts execution.

Schema drift is the most common root cause in production systems. New app releases might rename a field or drop an optional array. Older rows in the table still hold the legacy structure. When a batch job scans the full table, the missing item triggers code 22035.

Bad client input can also cause this failure during write operations. An upstream service might send an empty object instead of a nested payload. If a database trigger inspects that payload in strict mode, the write fails right away.

How to diagnose and fix the failure safely in production

To find the broken rows, you must inspect the target column safely. Do not grant broad write privileges to engineers who only need to debug. In PostgreSQL, you can grant the SELECT privilege on specific columns of a table. This lets an engineer read the broken JSON column without touching other table data.

If several team members need to check the data, set up group roles. You can grant column read rights to the group role and add users to it. Also, check that the PUBLIC role does not hold unwanted rights on your tables. By default, PUBLIC gets execute rights on functions, which an owner can revoke.

JSON Web Tokens (JWT) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

When you inspect live documents, watch out for private user data inside the JSON. Dynamic data masking rewrites matched fields like emails, phone numbers, card numbers, or national IDs in query results. This keeps sensitive payloads safe while developers look for missing keys.

Once you find the records with missing items, you have two ways to fix the query. The best fix is switching your JSON path expression from strict mode to lax mode. Lax mode converts missing items into empty results or null values instead of throwing an error.

Your second option is filtering out incomplete rows before the path check runs. You can add a filter clause that checks if the key exists first. You can also wrap the query logic with error handling behavior that returns a default value.

Preventing JSON path failures in future releases

You can stop code 22035 from coming back by tightening how data enters the table. Add a table check constraint that validates the JSON structure on every insert. Make sure the check uses lax mode or tests for key presence safely.

Keep your database schemas clean as your team builds test tables for debugging. In PostgreSQL 15 and later, regular users cannot create objects in the public schema by default. On older upgraded databases, admins should revoke create rights on the public schema from PUBLIC.

Finally, test new queries against a realistic sample of historical rows before deploying. Old rows almost always hold edge cases that fresh test data will miss.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres, inline in the Postgres wire protocol. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails refuse bad deletes or drops with a real Postgres error, or hold risky queries for approval. On the way back, hoop.dev data masking rewrites sensitive values in returned rows in memory, and every verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

What does SQLSTATE 22035 mean in PostgreSQL?

SQLSTATE 22035 is a standard data exception called no_sql_json_item. It means a JSON path query tried to read a key or array element that is missing from the document.

How do lax and strict JSON path modes differ?

Strict mode requires the exact path to exist and raises error 22035 if a key is missing. Lax mode ignores missing structural elements and returns an empty result or null value instead.

How can developers debug JSON columns without excess permissions?

Database admins can grant SELECT privileges on just the specific JSON column to a group role. Adding data masking also rewrites emails and card numbers in results during debugging.

The query runs. The emails stay hidden.