我们正在使用Airbyte将MongoDB数据同步到雪花中。由于某些原因,我们的JSON列表被同步为Java对象。
我正在尝试将数据转换为JSON格式,这样我就可以处理这些属性。
成本列中的Java对象行的示例:
"[Document{{currency=USD, value=815.00}}, Document{{currency=EUR, value=671.00}}, Document{{currency=GBP, value=579.00}}, Document{{currency=DKK, value=4992.00}}, Document{{currency=SEK, value=6760.00}}]"
我希望将行转换为以下格式
[{
"currency": "USD",
"value": 815.00
}, {
"currency": "EUR",
"value": 671.00
}, {
"currency": "GBP",
"value": 579.00
}, {
"currency": "DKK",
"value": 4992.00
}, {
"currency": "SEK",
"value": 6760.00
}]我怎样才能在Snowflake中做到这一点?
发布于 2021-11-10 15:54:18
您可以使用正则表达式,但这不是最优雅的方式:
set term='[Document{{currency=USD, value=815.00}}, Document{{currency=EUR, value=671.00}}, Document{{currency=GBP, value=579.00}}, Document{{currency=DKK, value=4992.00}}, Document{{currency=SEK, value=6760.00}}]';
select regexp_replace(regexp_replace(regexp_replace($term, 'Document',''), '}}', '}'), '{{', '{');我得到了:
[{currency=USD, value=815.00}, {currency=EUR, value=671.00}, {currency=GBP, value=579.00}, {currency=DKK, value=4992.00}, {currency=SEK, value=6760.00}]这可以进一步扩展,将currency替换为"currency"。
https://stackoverflow.com/questions/69913932
复制相似问题