JSON MySQL functions

Spanner supports the following JSON MySQL functions.You need to implement the MySQL functions in yourSpanner database before you can use them. For more information oninstalling the functions, seeInstall MySQL functions.

Function list

NameSummary
mysql.JSON_QUOTEQuotes a string as a JSON string literal.
mysql.JSON_UNQUOTEUnquotes a JSON string literal.

mysql.JSON_QUOTE

mysql.JSON_QUOTE(string_expression)

Description

Quotes a string as a JSON string literal. This function escapes specialcharacters as required by the JSON specification and encloses the result indouble quotes.

This function supports the following argument:

  • string_expression: TheSTRING value to quote.

Return data type

STRING

Example

The following example quotes an input string to make it a valid JSON string literal:

SELECTmysql.JSON_QUOTE('test')asjson_quoted;/*+------------------------------------------------------------------------------+| json_quoted                                                                  |+------------------------------------------------------------------------------+| "test"                                                                       |+------------------------------------------------------------------------------+*/

mysql.JSON_UNQUOTE

mysql.JSON_UNQUOTE(json_string_expression)

Description

Unquotes a JSON string literal, returning the original string value. This involvesinterpreting escape sequences within the input JSON string.

This function supports the following argument:

  • json_string_expression: TheSTRING value to unquote. This string should be a valid JSONstring literal, meaning it is typically enclosed in double quotes and hasinternal special characters escaped.

Return data type

STRING

Limitations

If the input string is not a valid JSON string literal (for example, it is notenclosed in double quotes or contains invalid escape sequences), this functionmight returnNULL or an empty string, depending on the specific input and theunderlyingJSON_VALUE behavior.

Example

The following example unquotes a JSON string literal:

SELECTmysql.JSON_UNQUOTE('\"test\"')asjson_unquoted;/*+----------------------------------------------------------------------------+| json_unquoted                                                              |+----------------------------------------------------------------------------+| test                                                                       |+----------------------------------------------------------------------------+*/

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.