bigquery提取的信息来自存储为字符串数据类型的JSON字符串

问题描述 投票:0回答:2
MyBQ表由BQ模块(Load_table_from_dataframe)填充到一个表中,并将其作为字符串类型(包括`````````````````````````````````````````````````````````````'')'

```json{ "number": 123, "date": "2020-11-01", "last_date": "2020-12-30" }```

enter image description here 我正在尝试使用多种方法提取键,但我的零件是无效的,因此我必须强行将``在空白中替换为空白并提取信息。我认为这个论坛可以比我更好地帮助我。 below代码有效,但我认为这不是从JSON中提取的正确方法

SELECT REPLACE(json_extract(json_extract((replace(REPLACE(FIELD_NAME,"```json",""),"```","")),"$"),"$[number]"),"\"","") as number FROM Table

您可以使用以下查询:

with table AS (
select json_object(
    'number', 123,
    'date', '2020-11-01',
    'last_date','2020-12-30',
    'array', ['0','1','2']
) as json
)
select 
 json_value(json, '$.number') as number -- To get the number
 , json_value(json, '$.date') as date_ -- To get the date
 , json_value_array(json, '$.array') as array_ -- To get the array
 , json_value(json, '$.object.foo') as foo -- To get the value of foo
 , json_value(json, '$.object.bar') as bar -- To get the value of bar
from table
sql arrays json regex google-bigquery
2个回答

0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.