如何在 AWS Athena 中解析 Json?

How to parsing Json in AWS Athena?

我想解析 Athena 中的 JSON 列,但我在其中一列中遇到问题。该列包含一个转义字符。不知道是不是这个问题。我想联系消息。您可以在 Return 下看到下面的示例数据和消息。谢谢

Sample Code 
CAST(json_extract_scalar(callparameters, '$return.Message') AS VARCHAR) AS Message

这是JSON。

{"inputs":{"usagespecid":"null","playsessionid":"null","satellitetypecd":"\"ERU\"","channelcontentid":"231"},
"return":"{\"Message\":\"Do not person you have called \"}"}    {"date":"2021-07-26","epoch":"1627"}    {"userpartyid":"23","userloginkey":"23","usercountrycode":"br","sessionkey":"23","client":{"name":"SMR","id":"1"},"usermainsatellitetype":"DS","userserviceaccountids":["23"],"usergeolocationid":"53","userpartyroleid":"76"}

如果您只获取包含 return 的对象,您可以使用 json_parsereturn 解析为 json,因为它包含编码字符串而不是 json 对象:

WITH dataset AS (
    SELECT * FROM (VALUES          
       (JSON '{
   "inputs":{
      "usagespecid":"null",
      "playsessionid":"null",
      "satellitetypecd":"\"ERU\"",
      "channelcontentid":"231"
   },
   "return":"{\"Message\":\"Do not person you have called \"}"
}')
 ) AS t (json_string))


SELECT json_extract_scalar(json_parse(json_extract_scalar(json_string, '$.return')), '$.Message')
FROM dataset

输出:

_col0
Do not person you have called