return NULL when all it should do is to add a second key?
Both functions involved are defined as being STRICT (null on null input). You need to COALSESCE SQL NULL to JSON 'null' to obtain the result you desire. This is a general truth when dealing with the JSON type in PostgreSQL.