Product Solutions Support
Try MemSQL

JSON_SET_<type>

This is a set of three JSON functions, which sets the value of a given key in a JSON map or array.

Maps are in the form:

{"a":1, "b":2, "c": [3,4,5]}

And arrays are in the form:

[1, 2, 3]

If the keyname does not exist in a map, it will be added. If it does exist, the value will be overwritten. If an array index is past the end of the array, intervening values will be set to NULL.

Return Type

Examples

mysql> select json_set_double('{"a":1, "b":2}', 'z', 26) as set_z;
+----------------------+
| set_z                |
+----------------------+
| {"a":1,"b":2,"z":26} |
+----------------------+

mysql> select json_set_double('[1,2,3]', 4, 26) as set_4;
+-----------------+
| set_4           |
+-----------------+
| [1,2,3,null,26] |
+-----------------+
Info

A JSON or Javascript null value is distinct from SQL NULL.

Was this article useful?