Extracts strings from a standard JSON string based on a set of input keys, such as (key1,key2,...)
.
Syntax
string json_tuple(string <json>, string <key1>, string <key2>,...)
Parameters
json: required. A value of the STRING type. This parameter specifies a standard JSON string.
key: required. A value of the STRING type. This parameter is used to describe the
path
of a JSON object in the JSON string. The value cannot start with a dollar sign ($). You can enter multiple keys at a time. MaxCompute parses JSON objects by using.
or['']
. If a key in a JSON object contains a period(.)
,['']
can be used.
Return value
A value of the STRING type is returned.
If json is empty or invalid, null is returned.
If key is empty, invalid, or does not exist in the JSON string, null is returned.
If json is valid and key exists, the related string is returned.
This function can parse JSON data that contains Chinese characters.
This function can parse nested JSON data.
This function can parse JSON data that contains nested arrays.
The parsing action is equivalent to the execution of GET_JSON_OBJECT along with
set odps.sql.udf.getjsonobj.new=true;
. To obtain multiple objects from a JSON string, you must call the GET_JSON_OBJECT function multiple times. As a result, the JSON string is parsed multiple times. The JSON_TUPLE function allows you to enter multiple keys at a time and the JSON string is parsed only once. JSON_TUPLE is more efficient than GET_JSON_OBJECT.JSON_TUPLE is a user-defined table-valued function (UDTF). If you want to select some columns from a table, use JSON_TUPLE together with the LATERAL VIEW clause.
Related functions
JSON_TUPLE is a complex type function or a string function.
For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.
For more information about functions related to string searches and conversion, see String functions.