Skip to content

JSON_ARRAY

  • value: The value parameter refers to the value you want to include in the JSON array. This could be an integer, a string, a boolean, another JSON array, or a JSON object. These values can be obtained from various data types in SQL, including character strings, numeric data, date-time data, and binary data. The order of these values in the array corresponds directly to the order in which they are inserted in the array.
  • value…: The ellipsis indicates that multiple values can be provided to the function, each separated by a comma. Like the first value, subsequent values will be included in the JSON array in the order they are provided. If no values are provided, the function returns an empty JSON array.
SELECT JSON_ARRAY('foo', 'bar', 'baz');
["foo", "bar", "baz"]

In the given example, the JSON_ARRAY() function in MySQL is used to create a JSON array containing 3 elements: ‘foo’, ‘bar’, ‘baz’. The function returns this as a single JSON array.