Bug #118856 json_objectagg throws inappropriate "no null member names" error in unreachable case.
Submitted: 19 Aug 23:36 Modified: 20 Aug 15:15
Reporter: Dmitriy P Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:8.0.35 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: json_objectagg, null

[19 Aug 23:36] Dmitriy P
Description:
In attempting to bypass a scenario where json_objectagg() might be fed a NULL value for the property key, I wrapped it in a conditional statement.

However, despite the condition not being met, it appears that the 'key = NULL' test is still performed and triggers an error). 

I have also tested this on DB-fiddle with v9, with the same result.
 

How to repeat:
select if(0, json_objectagg(null, 'text'), 'else')

> Error in query (3158): JSON documents may not contain NULL member names.

Suggested fix:
The above query should return 'else', not an error.
[20 Aug 6:08] MySQL Verification Team
Hi,

Sorry but this is not a bug, it is how parser woks. You can try instead using something like

select json_objectagg(COALESCE(null, 'xxx'), 'text')