PostgreSQL Error 2203E Too Many JSON Object Members
In this article
PostgreSQL error 2203E occurs when a JSON object exceeds the maximum allowed number of members—1,000 by default. This limit exists to prevent excessive memory usage and performance degradation during JSON parsing. The error is not a bug but a safety feature. To resolve it, you must reduce the number of keys in your JSON object or adjust PostgreSQL’s configuration if necessary. No external tools or third-party software are required.
What You'll Need
- Access to a PostgreSQL database server (version 9.4 or later)
- Privileges to run SQL commands and modify configuration files (if adjusting limits)
- A text editor to view or edit postgresql.conf (for advanced users)
- Knowledge of the JSON data structure causing the issue (e.g., from an application, API, or import script)
Step-by-Step
- Identify the exact JSON value causing the error by reviewing the error log or application output. The error message typically includes the problematic field name or query. Example:
ERROR: 2203E: too many JSON object membersfollowed by a query snippet. - Open your SQL client (e.g., psql, pgAdmin, DBeaver) and run a query to inspect the JSON data. Use
SELECT json_column FROM your_table WHERE json_column IS NOT NULL LIMIT 1;to retrieve one sample record with the problematic JSON. - Copy the raw JSON string from the result and paste it into a JSON validator tool like jsonlint.com. This will highlight the structure and count the number of top-level keys. If it exceeds 1,000, you’ve confirmed the issue.
- Reduce the number of members by restructuring the data. Instead of storing 1,500 individual key-value pairs in one JSON object, group related items into nested objects or arrays. For example, replace {"a1":1, "a2":2, ..., "a1500":1500} with to break the count into sub-objects of under 1,000 each.
- If the JSON comes from an external source like an API or file import, modify the source application or script to emit smaller JSON objects. For example, split large datasets into multiple records or use arrays of objects instead of a single object with many keys.
- After restructuring, test the updated JSON by inserting it into a test table:
INSERT INTO your_table (json_column) VALUES ('{"new_structure": "valid"}');. Ensure the INSERT succeeds without error. - If restructuring isn’t feasible and you control the PostgreSQL server, you can increase the limit by editing
postgresql.conf. Locate the linemax_json_object_members = 1000(if not present, add it under the JSON settings section). Change the value to a higher number, e.g.,max_json_object_members = 2000. Save the file. - Restart the PostgreSQL service using your OS’s service manager:
sudo systemctl restart postgresql(Linux) or through Windows Services. Confirm the service starts without errors. - After restart, verify the new setting is active by running
SHOW max_json_object_members;in your SQL client. It should return your new value. - Test the original query again to confirm the error no longer appears.
Common Mistakes
- Trying to fix the error by escaping quotes or reformatting whitespace—this does nothing, as the limit is on the number of members, not the size in bytes.
- Assuming the error is caused by JSON string length rather than member count. A 10,000-character JSON with 500 keys will work; a 500-character JSON with 1,200 keys will fail.
- Editing the wrong configuration file. PostgreSQL may have multiple config files (e.g., in different data directories). Use
SHOW config_file;to find the correct one. - Forgetting to restart PostgreSQL after changing
postgresql.conf. Settings are not reloaded on query execution. - Increasing the limit without understanding the performance impact. Each additional member increases memory and CPU overhead during parsing, which can slow down queries or cause instability under load.
Tips
- Design your JSON schema to use arrays of objects instead of wide objects. For example, use
[{"id":1,"name":"A"},{"id":2,"name":"B"}]rather than{"1":"A","2":"B"}. This is more scalable and avoids the member limit entirely. - Use PostgreSQL’s
jsonbtype instead ofjsonfor better performance and indexing, even if you’re not changing the structure. It’s more efficient and less prone to parsing issues. - When importing data, validate JSON structure before insertion. Use a script in Python, Node.js, or another language to count keys and warn or split records before sending to PostgreSQL.
- Monitor your JSON-heavy tables with periodic queries like
SELECT length(json_column::text), jsonb_object_keys(json_column) FROM your_table WHERE json_column IS NOT NULL ORDER BY length DESC LIMIT 5;to catch large objects early. - Document your JSON schema internally. If multiple teams use the same tables, ensure everyone knows the 1,000-member limit and designs accordingly.
Troubleshooting
If the error persists after following the steps above, first confirm the JSON has been correctly modified by checking the actual stored value. Run SELECT json_column FROM your_table WHERE id = [problematic_id]; and manually count the keys. If you still see more than 1,000, the update didn’t take effect—retry the update query with a confirmed smaller structure.
If you increased the limit in postgresql.conf but SHOW max_json_object_members; returns 1000, check for typos in the configuration file. Ensure the setting is not commented out (no # at the start). Also verify you edited the correct file by running SHOW config_file; and opening that exact path.
If restarting PostgreSQL fails, check the server logs (usually in /var/log/postgresql/ on Linux or the data directory’s log folder on Windows). Look for syntax errors in the config file or permission issues. If PostgreSQL won’t start, revert the change and restart to restore service.
If you cannot modify the source application or the JSON comes from an unchangeable third-party system, consider storing the data as a text field and parsing it in your application layer instead of using PostgreSQL’s JSON functions.
Frequently Asked Questions
Can I disable the 1,000-member limit entirely?
No. PostgreSQL enforces a hard upper limit of 10,000 members, even if you set max_json_object_members higher. You cannot bypass this safety cap.
Does this limit apply to nested objects too?
Yes. Each object, regardless of nesting level, counts its own members. A parent object with 500 keys and two child objects with 600 keys each will still fail because each child exceeds the limit.
Why does PostgreSQL have this limit at all?
To prevent malicious or malformed JSON from consuming excessive memory and crashing the server. A single object with 100,000 members could use gigabytes of RAM during parsing.
Can I use JSON arrays instead to avoid this error?
Yes. Arrays are not subject to the member count limit. Use [{"key1":"val1"}, {"key2":"val2"}] instead of {"key1":"val1", "key2":"val2"} for large datasets.
Is this limit the same in all PostgreSQL versions?
The default limit of 1,000 has been consistent since JSON support was added in version 9.4. The configuration option max_json_object_members was introduced in version 14.
Will this error affect JSONB columns too?
Yes. The limit applies equally to both json and jsonb types. The storage format doesn’t change the parsing rules.