12.16.4 Functions That Modify JSON Values
The functions in this section modify JSON values and return the result.
-
JSON_ARRAY_APPEND(json_doc,path,val[,path,val] ...)Appends values to the end of the indicated arrays within a JSON document and returns the result. Returns
NULLif any argument isNULL. An error occurs if thejson_docargument is not a valid JSON document or anypathargument is not a valid path expression or contains a*or**wildcard.The path-value pairs are evaluated left to right. The document produced by evaluating one pair becomes the new value against which the next pair is evaluated.
If a path selects a scalar or object value, that value is autowrapped within an array and the new value is added to that array. Pairs for which the path does not identify any value in the JSON document are ignored.
mysql> SET @j = '["a", ["b", "c"], "d"]'; mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql> SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]', 2) | +----------------------------------+ | [["a", 2], ["b", "c"], "d"] | +-------------