[英]Unexpected end of JSON input at undefined line XXXX, columns xx-xx while reading in BigQuery
I have a table in Bigquery which has 2 columns - job_id
and json_column
(string which is in JSON format).我在 Bigquery 中有一个表,它有 2 列 - job_id
和json_column
(JSON 格式的字符串)。 When I tried to read the data and identify some objects it gives me error as below:当我试图读取数据并识别一些对象时,它给我错误如下:
SyntaxError:Unexpected end of JSON input at undefined line XXXX, columns xx-xx
It Always gives me line 5931 and second time I execute again it gives line 6215.它总是给我第 5931 行,第二次我再次执行它给了第 6215 行。
If it's related to JSON structure issue, how can I know which row/ job_id
that number 5931 corresponds to?如果它与JSON结构问题有关,我如何知道数字5931对应于哪个行/ job_id
? If I subset for a specific job_id
, it returns the values but when I tried to execute on the complete table, I got this error.如果我为特定的job_id
设置子集,它会返回值,但是当我尝试在整个表上执行时,出现此错误。 I tried looking at the job_id
at the row_numbers mentioned and code works fine for those job_id
s.我试着查看提到的 row_numbers 处的job_id
,代码对那些job_id
工作正常。
Do you think its JSON structure issue and how to identify which row/ job_id
has this Issue?你认为它的 JSON 结构问题以及如何识别哪个行/ job_id
有这个问题?
Code:代码:
CREATE TEMPORARY FUNCTION CUSTOM_JSON_EXTRACT(json STRING, json_path STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS """
var result = jsonPath(JSON.parse(json), json_path);
if(result){return result;}
else {return [];}
"""
OPTIONS (
library="gs://json_temp/jsonpath-0.8.0.js"
);
SELECT job_id,dist,gm,sub_gm
FROM lz_fdp_op.fdp_json_file,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.OpsLocationInfo.iDistrictId')) dist ,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.GeoMarketInfo.Geo')) gm,
UNNEST(CUSTOM_JSON_EXTRACT(trim(conv_column), '$.Project.GeoMarketInfo.SubGeo')) sub_gm
Would this work for you?这对你有用吗?
WITH
T AS (
SELECT
'1000149.04.14' AS job_id,
'{"Project":{"OpsLocationInfo":{"iDistrictId":"A"},"GeoMarketInfo":{"Geo":"B","SubGeo":"C"}}}' AS conv_column
)
SELECT
JSON_EXTRACT_SCALAR(conv_column, '$.Project.OpsLocationInfo.iDistrictId') AS dist,
JSON_EXTRACT_SCALAR(conv_column, '$.Project.GeoMarketInfo.Geo') AS gm,
JSON_EXTRACT_SCALAR(conv_column, '$.Project.GeoMarketInfo.SubGeo') AS sub_gm
FROM
T
BigQuery JSON Functions docs: https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions BigQuery JSON 函数文档: https ://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions
how can I read multiple arrays in an object in JSON without using unnest?如何在不使用 unnest 的情况下读取 JSON 对象中的多个数组?
Can you explain better with an input sample your comment?你能用输入样本更好地解释你的评论吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.