Parses the data that matches a JSON path in a JSON expression. If the JSON path that you specify is invalid, an error is reported.
Syntax
json json_extract(<json>, <json_path>)
Parameters
json: required. This parameter specifies the JSON expression that you want to process.
json_path: required. This parameter specifies the JSON path of the value that you want to be returned.
Return value
The return value is of the JSON type.
Examples
Example 1: Obtain the value of the key a from a JSON object.
select json_extract(json '{"a":1, "b":2}', '$.a');
The following result is returned:
+-----+ | _c0 | +-----+ | 1 | +-----+
Example 2: NULL is returned if the specified key does not exist in the JSON object.
select json_extract(json '{"a":1, "b":2}', 'strict $.c');
The following result is returned:
+-----+ | _c0 | +-----+ | NULL | +-----+
Example 3: The error message
Invalid argument - Param json path $invalid_json_path is invalid
is returned if the JSON path that you specified is invalid.select json_extract(json '{"a":1, "b":2}', '$a');
The following result is returned:
-- An error message is returned. Invalid argument - Param json path $invalid_json_path is invalid
Related functions
JSON_EXTRACT is a complex type 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.