如何在 Google Data Studio、Big Query、Json 中阅读 Json
How to read Json in Google Data Studio, Big Query, Json
我使用 Big Query 作为云数据仓库,使用 DataStudio 进行可视化。
在 Big Query 中,我有一个 table,其中一个名为 data
的列写在 JSON 中。我只想提取“city”字段中的内容。
下面有人给我的这个公式用于提取字段“title”中的内容。我用它在 DataStudio 中创建了一个字段。
REPLACE(REGEXP_EXTRACT(data, '"title":(.+)","ur'), "\"", "")
因此,我尝试了多种方法将此公式重新用于“城市”字段,但没有奏效。我不明白这段代码。
我的列数据里面有什么:
{
"address":{
"city":"This is what i want",
"country":"blablabla",
"lineAdresse":"blablabla",
"region":"blablabla",
"zipCode":"blablabla"
},
"contract":"blablabla",
"dataType":"blablabla",
"description":"blablabla",
"endDate":{
"_seconds":1625841747,
"_nanoseconds":690000000
},
"entreprise":{
"denomination":"blabla",
"description":"1",
"logo":"blablabla",
"blabla":"blablabla",
"verified":"false"
},
"id":"16256R8TOUHJG",
"idEntreprise":"blablabla",
"jobType":"blablabla",
"listInfosRh":null,
"listeCandidats":[
],
"field":0,
"field":0,
"field":14,
"field":"1625834547690",
"field":true,
"field":"",
"field":"ref1625834547690",
"skills":[
"field",
"field",
"field"
],
"startDate":{
"_seconds":1625841747,
"_nanoseconds":690000000
},
"status":true,
"title":"this I can extract",
"urlRedirection":"blablabla",
"validated":true
}
如果有人知道放入 Data Studio 以提取其中内容的公式 city
并且可以向我解释,这将有很大帮助。
这是我试过的公式,但我得到的结果是“空”:
REPLACE(REGEXP_EXTRACT(data,'"city":/{([^}]*)}/'),"\"","") >>null
我试过这个,但它不会停在城市里。我得到了地址、地区、邮政编码和所有其他信息:
REPLACE(REGEXP_EXTRACT(data, '"city":(.+)","ur'), "\"", "")
可以通过忽略任何层次结构并仅查找特定字段来解析文本字段中的 JSON。在您的情况下,字段名称是 title
和 city
。请注意,此方法无法保存用户输入的数据:通过设置 "city":"\" hide \""
的值,脚本无法提取城市。
select *,
REGEXP_EXTRACT(data, r'"title":\s*"([^"]+)') as title,
REGEXP_EXTRACT(data, r'"city":\s*"([^"]+)') as city
from(
Select ' { "address":{ "city":"This is what i want", "country":"blablabla", "lineAdresse":"blablabla", "region":"blablabla", "zipCode":"blablabla" }, "contract":"blablabla", "dataType":"blablabla", "description":"blablabla", "endDate":{ "_seconds":1625841747, "_nanoseconds":690000000 }, "entreprise":{ "denomination":"blabla", "description":"1", "logo":"blablabla", "blabla":"blablabla", "verified":"false" }, "id":"16256R8TOUHJG", "idEntreprise":"blablabla", "jobType":"blablabla", "listInfosRh":null, "listeCandidats":[ ], "field":0, "field":0, "field":14, "field":"1625834547690", "field":true, "field":"", "field":"ref1625834547690", "skills":[ "field", "field", "field" ], "startDate":{ "_seconds":1625841747, "_nanoseconds":690000000 }, "status":true, "title":"this I can extract", "urlRedirection":"blablabla", "validated":true }' as data
)
我使用 Big Query 作为云数据仓库,使用 DataStudio 进行可视化。
在 Big Query 中,我有一个 table,其中一个名为 data
的列写在 JSON 中。我只想提取“city”字段中的内容。
下面有人给我的这个公式用于提取字段“title”中的内容。我用它在 DataStudio 中创建了一个字段。
REPLACE(REGEXP_EXTRACT(data, '"title":(.+)","ur'), "\"", "")
因此,我尝试了多种方法将此公式重新用于“城市”字段,但没有奏效。我不明白这段代码。
我的列数据里面有什么:
{
"address":{
"city":"This is what i want",
"country":"blablabla",
"lineAdresse":"blablabla",
"region":"blablabla",
"zipCode":"blablabla"
},
"contract":"blablabla",
"dataType":"blablabla",
"description":"blablabla",
"endDate":{
"_seconds":1625841747,
"_nanoseconds":690000000
},
"entreprise":{
"denomination":"blabla",
"description":"1",
"logo":"blablabla",
"blabla":"blablabla",
"verified":"false"
},
"id":"16256R8TOUHJG",
"idEntreprise":"blablabla",
"jobType":"blablabla",
"listInfosRh":null,
"listeCandidats":[
],
"field":0,
"field":0,
"field":14,
"field":"1625834547690",
"field":true,
"field":"",
"field":"ref1625834547690",
"skills":[
"field",
"field",
"field"
],
"startDate":{
"_seconds":1625841747,
"_nanoseconds":690000000
},
"status":true,
"title":"this I can extract",
"urlRedirection":"blablabla",
"validated":true
}
如果有人知道放入 Data Studio 以提取其中内容的公式 city
并且可以向我解释,这将有很大帮助。
这是我试过的公式,但我得到的结果是“空”:
REPLACE(REGEXP_EXTRACT(data,'"city":/{([^}]*)}/'),"\"","") >>null
我试过这个,但它不会停在城市里。我得到了地址、地区、邮政编码和所有其他信息:
REPLACE(REGEXP_EXTRACT(data, '"city":(.+)","ur'), "\"", "")
可以通过忽略任何层次结构并仅查找特定字段来解析文本字段中的 JSON。在您的情况下,字段名称是 title
和 city
。请注意,此方法无法保存用户输入的数据:通过设置 "city":"\" hide \""
的值,脚本无法提取城市。
select *,
REGEXP_EXTRACT(data, r'"title":\s*"([^"]+)') as title,
REGEXP_EXTRACT(data, r'"city":\s*"([^"]+)') as city
from(
Select ' { "address":{ "city":"This is what i want", "country":"blablabla", "lineAdresse":"blablabla", "region":"blablabla", "zipCode":"blablabla" }, "contract":"blablabla", "dataType":"blablabla", "description":"blablabla", "endDate":{ "_seconds":1625841747, "_nanoseconds":690000000 }, "entreprise":{ "denomination":"blabla", "description":"1", "logo":"blablabla", "blabla":"blablabla", "verified":"false" }, "id":"16256R8TOUHJG", "idEntreprise":"blablabla", "jobType":"blablabla", "listInfosRh":null, "listeCandidats":[ ], "field":0, "field":0, "field":14, "field":"1625834547690", "field":true, "field":"", "field":"ref1625834547690", "skills":[ "field", "field", "field" ], "startDate":{ "_seconds":1625841747, "_nanoseconds":690000000 }, "status":true, "title":"this I can extract", "urlRedirection":"blablabla", "validated":true }' as data
)