PARSE_JSON converts a JSON-formatted STRING into BigQuery’s native JSON type so you can query nested properties directly.
PARSE_JSON converts a JSON-formatted STRING into a native JSON value, allowing dot-notation and JSON functions for fast, repeated access.
Use PARSE_JSON(string_expr)
or SAFE.PARSE_JSON(string_expr)
. The safe variant returns NULL instead of an error when the input is invalid.
SELECT PARSE_JSON('{"id":1,"name":"Widget"}') AS product_json;
Assume Orders.order_details
is a STRING. Parse once, then access nested fields.
SELECT
details.customer_id,
details.items[OFFSET(0)].product_id AS first_item
FROM (
SELECT PARSE_JSON(order_details) AS details FROM Orders)
WHERE order_date > CURRENT_DATE() - 30;
Choose PARSE_JSON to treat the whole document as JSON for multiple field reads or storage. Use JSON_EXTRACT(_SCALAR) for a single, ad-hoc pull from a STRING.
SAFE.PARSE_JSON
to keep pipelines running.BigQuery errors on BYTES or JSON types. Cast: PARSE_JSON(CAST(raw AS STRING))
.
Malformed JSON stops the query. Use SAFE.PARSE_JSON
and handle NULLs with IFNULL
.
Google Cloud docs: PARSE_JSON.
No. PARSE_JSON only converts a STRING to JSON. Use dot notation or JSON_QUERY/JSON_VALUE after parsing.
Yes. Arrays remain intact. Access elements with [OFFSET(n)]
or by UNNEST
.
No. It is part of BigQuery Standard SQL only.