无法从 BigQUERY 中的 json 数组列中提取值

Unable to extract value from json array column in BigQUERY

我在 BigQuery 中有一个 table 列,采用 JSON 数组格式,其中一行像 {"role":"SuperAdmin","_id":"abcd","userId":"efgh"}。 BigQuery 中的此列架构是重复模式。我的目标是提取该列中所有行的 userId 值。

我尝试使用 JSON 函数,例如 json_valuejson_extract:

select  json_value(column_name, '$.users.userId') as userId,  from table_name

但出现以下错误:

No matching signature for function JSON_VALUE for argument types: ARRAY<STRING>, STRING. Supported signature: JSON_VALUE(STRING, [STRING]) at [2:3]

请问我该怎么做?

因为它是重复的,所以你需要先取消嵌套。

给定以下示例:

with sample_data as (
    select ['{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}','{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}','{"role":"SuperAdmin","_id":"abcd","userId":"efgh"}'] as users
)

select json_value(user, '$.userId') as userId
from sample_data , UNNEST(users) user

return是: