json - JSONPaths 文件:解析 JSON 数组中包含的 JSON 对象
问题描述
我有以下 JSON 形式的行:
[
{
"id": 1,
"costs": [
{
"blue": 100,
"location":"courts",
"sport": "football"
}
]
}
]
我想将其上传到红移表中,如下所示:
id | blue | location | sport
--------+------+---------+------
1 | 100 | courts |football
以下 JSONPaths 文件不成功:
{
"jsonpaths": [
"$.id",
"$.costs[0].blue",
"$.costs[0].location",
"$.costs[0].sport"
]
}
Redshift 返回以下错误代码:
err_code: 1216 Invalid JSONPath format: Member is not an object.
如何更改 jsonpaths 文件以便能够根据需要上传 json?
解决方案
John Rotenstein在评论中提供了答案。我只是在这里正式确定答案。
如文档中所示,输入 JSON 记录必须是 JSON 对象的新行分隔序列。这些示例将 JSON 对象显示为打印得很漂亮,但通常记录的输入流将是每行一个 JSON 对象。
{ "id": 1, "costs": [ { "blue": 100, "location":"courts", "sport": "football" } ] }
{ "id": 2, "costs": [ { "blue": 200, "location":"fields", "sport": "cricket" } ] }
因此,从技术上讲,输入记录流不需要是有效的 JSON,而是分隔的有效 JSON 对象流。
推荐阅读
- javascript - 如何在 Excel VBA 中使用 Selenium Webdriver 滚动下拉菜单
- ios - *已解决* 在分发模式下无法从 NSUserDefault 获取值
- java - REST API 调用的最佳实践是什么?
- vue.js - Vuejs在选中单选按钮时显示某些div
- jquery - 在 jQuery 中旋转 else
- flutter - 使用带有意图和发布参数的 Flutter Launch 默认浏览器
- linux - 主服务器和从服务器之间的 rsync 到远程存储库存储
- angularjs - 使用带有两个 50% div 的 flex 创建滚动条
- gradle - Intellij IDEA Plugin Gradle 开发 - 为现有类生成代码
- python - 如何使用 matplotlib 小部件塑造按钮?