12.17 JSON Functions

The functions described in this section perform operations on JSON values. For discussion of the note 'JSON': json. data type and additional examples showing how to use these functions, see note json::.

For functions that take a JSON argument, an error occurs if the argument is not a valid JSON value. Arguments parsed as JSON are indicated by JSON_DOC; arguments indicated by VAL are not parsed.

Functions that return JSON values always perform normalization of these values (see *note json-normalization::), and thus orders them. The precise outcome of the sort is subject to change at any time; do not rely on it to be consistent between releases.

Unless otherwise indicated, the JSON functions were added in MySQL 5.7.8.

A set of spatial functions for operating on GeoJSON values is also available. See *note spatial-geojson-functions::.

 File: manual.info.tmp, Node: json-function-reference, Next: json-creation-functions, Prev: json-functions, Up: json-functions

12.17.1 JSON Function Reference

JSON Functions

Name Description IntroducedDeprecated

'->'

Return value from JSON column after evaluating path; equivalent to JSON_EXTRACT().

'->>'

Return value 5.7.13 from JSON
column after evaluating path and unquoting the result; equivalent to JSON_UNQUOTE(JSON_EXTRACT()).

'JSON_APPEND()'

Append data to Yes JSON document

'JSON_ARRAY()'

Create JSON array

'JSON_ARRAY_APPEND()'

Append data to JSON document

'JSON_ARRAY_INSERT()'

Insert into JSON array

'JSON_CONTAINS()'

Whether JSON document contains specific object at path

'JSON_CONTAINS_PATH()'

Whether JSON document contains any data at path

'JSON_DEPTH()'

Maximum depth of JSON document

'JSON_EXTRACT()'

Return data from JSON document

'JSON_INSERT()'

Insert data into JSON document

'JSON_KEYS()'

Array of keys from JSON document

'JSON_LENGTH()'

Number of elements in JSON document

'JSON_MERGE()'

Merge JSON 5.7.22 documents,
preserving duplicate keys. Deprecated synonym for JSON_MERGE_PRESERVE()

'JSON_MERGE_PATCH()'

Merge JSON 5.7.22 documents,
replacing values of duplicate keys

'JSON_MERGE_PRESERVE()'

Merge JSON 5.7.22 documents,
preserving duplicate keys

'JSON_OBJECT()'

Create JSON object

'JSON_PRETTY()'

Print a JSON 5.7.22 document in
human-readable format

'JSON_QUOTE()'

Quote JSON document

'JSON_REMOVE()'

Remove data from JSON document

'JSON_REPLACE()'

Replace values in JSON document

'JSON_SEARCH()'

Path to value within JSON document

'JSON_SET()'

Insert data into JSON document

'JSON_STORAGE_SIZE()'

Space used for 5.7.22 storage of
binary representation of a JSON document

'JSON_TYPE()'

Type of JSON value

'JSON_UNQUOTE()'

Unquote JSON value

'JSON_VALID()'

Whether JSON value is valid

MySQL 5.7.22 and later supports two aggregate JSON functions 'JSON_ARRAYAGG()' and 'JSON_OBJECTAGG()'. See *note aggregate-functions-and-modifiers::, for descriptions of these.

Also beginning with MySQL 5.7.22:

For complete descriptions of these two functions, see *note json-utility-functions::.

 File: manual.info.tmp, Node: json-creation-functions, Next: json-search-functions, Prev: json-function-reference, Up: json-functions

12.17.2 Functions That Create JSON Values

The functions listed in this section compose JSON values from component elements.

You can also obtain JSON values by casting values of other types to the 'JSON' type using 'CAST(VALUE AS JSON)'; see *note json-converting-between-types::, for more information.

Two aggregate functions generating JSON values are available (MySQL 5.7.22 and later). 'JSON_ARRAYAGG()' returns a result set as a single JSON array, and 'JSON_OBJECTAGG()' returns a result set as a single JSON object. For more information, see *note aggregate-functions-and-modifiers::.

 File: manual.info.tmp, Node: json-search-functions, Next: json-modification-functions, Prev: json-creation-functions, Up: json-functions

12.17.3 Functions That Search JSON Values

The functions in this section perform search operations on JSON values to extract data from them, report whether data exists at a location within them, or report the path to data within them.

 File: manual.info.tmp, Node: json-modification-functions, Next: json-attribute-functions, Prev: json-search-functions, Up: json-functions

12.17.4 Functions That Modify JSON Values

The functions in this section modify JSON values and return the result.

 File: manual.info.tmp, Node: json-attribute-functions, Next: json-utility-functions, Prev: json-modification-functions, Up: json-functions

12.17.5 Functions That Return JSON Value Attributes

The functions in this section return attributes of JSON values.

 File: manual.info.tmp, Node: json-utility-functions, Prev: json-attribute-functions, Up: json-functions

12.17.6 JSON Utility Functions

This section documents utility functions that act on JSON values, or strings that can be parsed as JSON values. 'JSON_PRETTY()' prints out a JSON value in a format that is easy to read. 'JSON_STORAGE_SIZE()' shows the amount of storage space used by a given JSON value.

 File: manual.info.tmp, Node: gtid-functions, Next: aggregate-functions-and-modifiers, Prev: json-functions, Up: functions