Request a demo

BigQuery · JSON function

BigQuery JSON_VALUE_ARRAY

JSON_VALUE_ARRAY(json[, json_path]) extracts a JSON array of scalars as an ARRAY<STRING> with the quotes removed. Use it for tag lists, IDs and flags stored in JSON; it returns NULL if any element is an object or an array.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

JSON_VALUE_ARRAY is the array counterpart of JSON_VALUE: {"tags": ["sale", "new"]} with the path '$.tags' gives [sale, new] as ARRAY<STRING>. Numbers and booleans come back as text, so cast the elements when you need numbers. It replaces the deprecated JSON_EXTRACT_STRING_ARRAY.

It handles arrays of scalars only. If any element is an object or an array, the whole result is NULL; use JSON_QUERY_ARRAY for those. A missing path or a non-array value also returns NULL, and [] returns an empty array.

JSON null elements become SQL NULL elements. That is fine inside the query, but an array that reaches the result with a NULL in it fails with Array cannot have a null element. Filter the nulls out in an ARRAY subquery, or test membership directly with 'sale' IN UNNEST(JSON_VALUE_ARRAY(...)).

Syntax

JSON_VALUE_ARRAY(json_string_expr[, json_path])

JSON_VALUE_ARRAY(json_expr[, json_path])

Arguments and return value

ArgumentDescription
json_string_exprJSON-formatted text in a STRING.
json_exprA value of type JSON.
json_pathOptional constant JSONPath to the array, default $. Escape special keys with double quotes.

Returns: ARRAY<STRING>. NULL if the path is missing, isn't an array, or the array contains objects or arrays.

Examples

Tags and IDs as plain strings

SELECT
  JSON_VALUE_ARRAY('{"tags": ["sale", "new", "eco"]}', '$.tags') AS tags,
  JSON_VALUE_ARRAY(JSON '{"ids": [101, 102]}', '$.ids') AS ids_as_strings;
Result
tagsids_as_strings
[sale, new, eco][101, 102]

Rows whose JSON array contains a value

P3 has no tags key. Its NULL array makes the IN test false, so the row is filtered out.

WITH products AS (
  SELECT 'P1' AS sku, JSON '{"tags": ["sale", "new"]}' AS attrs UNION ALL
  SELECT 'P2', JSON '{"tags": ["new"]}' UNION ALL
  SELECT 'P3', JSON '{}'
)
SELECT sku
FROM products
WHERE 'sale' IN UNNEST(JSON_VALUE_ARRAY(attrs, '$.tags'))
ORDER BY sku;
Result
sku
P1

Convert to an INT64 array

SELECT
  ARRAY(
    SELECT CAST(id AS INT64)
    FROM UNNEST(JSON_VALUE_ARRAY('{"ids": [101, 102, 205]}', '$.ids')) AS id WITH OFFSET AS pos
    ORDER BY pos
  ) AS ids;
Result
ids
[101, 102, 205]

Objects give NULL; null elements must be filtered

Returning the tags array as is would fail, because its JSON null becomes a NULL element.

SELECT
  JSON_VALUE_ARRAY('{"items": [{"sku": "KB-1"}]}', '$.items') IS NULL AS objects_give_null,
  ARRAY(
    SELECT tag
    FROM UNNEST(JSON_VALUE_ARRAY('{"tags": ["sale", null, "new"]}', '$.tags')) AS tag WITH OFFSET AS pos
    WHERE tag IS NOT NULL
    ORDER BY pos
  ) AS tags_without_nulls;
Result
objects_give_nulltags_without_nulls
true[sale, new]

Common mistakes

  • Using it on arrays of objects. The result is NULL, not an error; use JSON_QUERY_ARRAY.
  • Returning arrays that contain JSON nulls. The query fails at output with "Array cannot have a null element"; drop the nulls in an ARRAY subquery.
  • Forgetting that elements are STRING. 101 IN UNNEST(JSON_VALUE_ARRAY(...)) fails with "No matching signature for operator IN UNNEST"; compare with '101' or cast the elements.
  • Using $['a.b'] escaping, which only the deprecated JSON_EXTRACT functions accept.

FAQ

How do I convert a JSON array to a BigQuery array?

For scalars, JSON_VALUE_ARRAY(json_col, '$.tags') returns ARRAY<STRING>. For objects, JSON_QUERY_ARRAY(json_col, '$.items') returns one JSON element per object.

How do I check if a JSON array contains a value?

WHERE 'sale' IN UNNEST(JSON_VALUE_ARRAY(attrs, '$.tags')). Rows without the key produce a NULL array, and IN UNNEST over it is false.

What is the difference between JSON_VALUE_ARRAY and JSON_EXTRACT_STRING_ARRAY?

They return the same arrays. JSON_VALUE_ARRAY is the recommended function and escapes special keys with double quotes; JSON_EXTRACT_STRING_ARRAY is deprecated and uses $['key'].

Errors you may hit

More JSON functions

All BigQuery JSON functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.