将一串"单引号"解析为 presto 中的 json



~我想像下面的代码一样强制转换一个"单引号"字符串。~


对不起,我改了问题。我将"单引号"替换为";双引号">

示例

WITH data as (
SELECT 
'{"svod": True, "awards": [], "copyright": "© ROI VISUAL / EBS All rights Reserved.", "providerId": "50176b59-9bae-40ed-bedd-167786953c73", "releaseYear": 2018, "rating_levels": {"drugs": "none", "theme": "none", "horror": "none", "language": "none", "violence": "none", "sex_and_nudity": "none", "imitable_behavior": "none"}, "display_runtime": "00:05:00", "production_company": "ROIVISUAL"}' as meta
)
SELECT 
-- json_parse(meta) -- X (Error : Cannot convert value to JSON)
cast(meta as json) as meta_json, -- O > "{"svod": True, "awards": [], "copyright": "© ROI VISUAL / EBS All rights Reserved.", "providerId": "50176b59-9bae-40ed-bedd-167786953c73", "releaseYear": 2018, "rating_levels": {"drugs": "none", "theme": "none", "horror": "none", "language": "none", "violence": "none", "sex_and_nudity": "none", "imitable_behavior": "none"}, "display_runtime": "00:05:00", "production_company": "ROIVISUAL"}"
json_extract_scalar(cast(meta as json), '$.providerId') as meta_providerId -- Empty Return
FROM data

预期结果

SELECT 
json_extract_scalar(cast(meta as json), '$.releaseYear'), -- 2018
json_extract_scalar(cast(meta as json), '$.providerId') -- "50176b59-9bae-40ed-bedd-167786953c73"
FROM data

我以前提到过这个,但没有成功。

  • 如何在presto中将varchar强制转换为MAP(varchar,varchar(
  • 如何在Presto中提取嵌套json数组对象中的键
  • Presto构建具有不同数据类型的JSON数组

你有什么建议吗?

谢谢!

您的JSON似乎无效。

使用"True"(带引号(或true(不带引号,小写(使JSON有效。

相关内容

  • 没有找到相关文章

最新更新