当字段包含 @ 符号时,如何使用函数从 Google BigQuery 中提取 json BigQuery Standard SQL

how do i extract json from Google BigQuery using a function when the field contains @ sign BigQuery Standard SQL

所以我的 table 看起来像这样

{"@timestamp":"2018-08-08T09:21:57.947+00:00","@version":"1","message":"bla bla"}

我可以使用下面的json函数提取消息部分

JSON_EXTRACT_SCALAR(log,'$.message') AS message

但是当我尝试以同样的方式提取时间戳时

JSON_EXTRACT_SCALAR(log,'$.@timestamp') AS timestamp

我收到错误 "Error: Unsupported operator in JSONPath: @" 关于正确语法的任何想法?

如果 JSON 键使用无效的 JSON 路径字符,您可以使用单引号和方括号 [' '] 转义这些字符。例如:

$['@timestamp']

SELECT 
 json_extract_scalar('{"@timestamp":"2018-08-08T09:21:57.947+00:00"}',"$['@timestamp']")

查看更多示例:JSON Functions in Standard SQL