MySQL raises ER_JSON_DOCUMENT_NULL_KEY (error 3158, SQLSTATE 22032) when a JSON document contains an object key that is NULL or an empty string.
ER_JSON_DOCUMENT_NULL_KEY occurs when MySQL parses a JSON object whose member name is NULL or empty. Replace NULL keys or convert the data before insertion to resolve the issue. The primary fix is to ensure every JSON object key is a valid, non-NULL string.
ER_JSON_DOCUMENT_NULL_KEY
MySQL error 3158, condition ER_JSON_DOCUMENT_NULL_KEY, is raised when the server validates or manipulates a JSON document that contains an object member whose key is NULL or an empty string.
The error is accompanied by SQLSTATE 22032 and the text "JSON documents may not contain NULL member names." It was introduced in MySQL 5.7.8 and applies to every subsequent version, including 8.x.
The error commonly appears during INSERT, UPDATE, or JSON function calls (such as JSON_SET or JSON_MERGE) when the supplied JSON string has an invalid object key.
It can also surface while loading data via LOAD DATA INFILE, importing dumps, or calling stored procedures that build JSON dynamically.
Blocking writes due to malformed JSON halts ETL pipelines and application requests, leading to data loss or downtime.
Because the error indicates structurally invalid data, ignoring it risks corrupting business logic and downstream analytics that rely on JSON consistency.
Upstream applications sometimes serialize objects that include null or undefined property names, producing JSON like {"":123} or {null:123}.
Building JSON strings via CONCAT or string interpolation can accidentally leave a key blank when a variable is NULL.
Converting XML, CSV, or relational rows into JSON with GROUP_CONCAT may yield empty keys when source column names are missing.
Older dumps from MySQL versions before strict JSON validation might already contain invalid keys that fail on reload in 5.7.8+.
Raised when a JSON string is syntactically invalid, such as missing braces or quotes.
Triggered when a JSON document exceeds the maximum nesting depth of 100 levels.
Occurs when a JSON path expression contains characters that do not match the column's character set.
Raised when an array index in a JSON path is out of range or malformed.
You can switch the column type to LONGTEXT, but you lose JSON functions, indexing, and validation. Fixing the data is strongly recommended.
No. MySQL rejects the statement entirely. You must supply valid JSON before the engine accepts it.
All versions from 5.7.8 onward enforce it, including the entire 8.x series.
Add JSON_VALID checks or unit tests in your CI pipeline, and use Galaxy's AI copilot to review migration scripts for JSON issues.