Cloud
json_extract_path
json_extract_path() function extracts json nested value from a specified path.
Syntax
The syntax of the json_extract_path() function is:
JSON_EXTRACT_PATH(from_json JSON, path TEXT[])
-
from_json: Thejsonvalue from which to extract. -
path: The path to extract.
Examples
These examples display how json_extract_path() extracts the “oxla” json sub-object from the specified path.
-
Use the query:
SELECT JSON_EXTRACT_PATH('{"f2":{"f3":1},"f4":{"f5":99,"f6":"oxla"}}', 'f4', 'f6');or
SELECT '{"f2":{"f3":1},"f4":{"f5":99,"f6":"oxla"}}'::JSON -> 'f4' -> 'f6';The query results:
+---------+ | f | +---------+ | "oxla" | +---------+ -
Run the query:
SELECT JSON_EXTRACT_PATH('{"a": 1, "b": {"x": "subtract", "y": "plus"}}', 'b', 'x') AS "bx", JSON_EXTRACT_PATH('{"a": 1, "b": {"x": "multiply", "y": "divide"}}', 'b', 'y') AS "by";The query returns:
+---------------+-------------+ | bx | by | +---------------+-------------+ | "subtract" | "divide" | +---------------+-------------+
Was this helpful?