I am using JSON_REPLACE to update the value of a key, but I am having a hard time figure out how to create the key before updating it if it does not exist.
This is how my query looks like.
$query_update = "UPDATE `forms` SET `conf` = JSON_REPLACE(`conf`, '$.title', '$title') WHERE id='32'";
Any idea how can I do that in the same query?
UPDATE
Thanks to the comments by Juan Eizmendi and Salman A below, changing JSON_REPLACE to JSON_SET resolved the problem.
The updated query looks like that
$query_update = "UPDATE `forms` SET `conf` = JSON_SET(`conf`, '$.title', '$title') WHERE id='32'";
JSON_SETdoes. if you only want to check for a key determine if a json valueJSON_REPLACEandJSON_SET