【问题标题】:JSONPaths file: Parse a JSON object contained within a JSON arrayJSONPaths 文件:解析 JSON 数组中包含的 JSON 对象
【发布时间】:2018-05-01 11:30:06
【问题描述】:

我有以下 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?

【问题讨论】:

  • 我认为这可能是因为您的表达式未包含在 {} 中,因此它不是有效的 JSON。
  • 感谢@JohnRotenstein。在我删除环绕行的 [] 后它起作用了。祝你有美好的一天!

标签: json amazon-redshift


【解决方案1】:

答案由 cmets 中的John Rotenstein 提供。我只是在这里正式给出答案。

documentation 所示,输入的 JSON 记录必须是 JSON 对象的新行分隔序列。这些示例显示 JSON 对象打印得非常漂亮,但通常记录的输入流将是每行一个 JSON 对象。

{ "id": 1, "costs": [ { "blue": 100, "location":"courts", "sport": "football" } ] }
{ "id": 2, "costs": [ { "blue": 200, "location":"fields", "sport": "cricket" } ] }

因此,从技术上讲,输入记录流不需要是有效的 JSON,而是分隔的有效 JSON 对象流。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    相关资源
    最近更新 更多