JOLT规范如何通过以下输入实现所需的结果?

时间:2017-10-18 20:37:12

标签: jolt

我遇到了将JSON有效负载转换为所需文档的麻烦。

我有以下输入:

{
  "events": [
    {
      "recipientId": "r0001"
    },
    {
      "recipientId": "r0002"
    }
  ],
  "networkResponseTime": 1234
}

期望的输出:

{
  "events": [
    {
      "recipientIds": "r0001",
      "networkResponseTime": 1234"
    },
    {
      "recipientIds": "r0002",
      "networkResponseTime": 1234"
    }
  ]
}

这个例子的JOLT规范怎么样?

到目前为止,我已经这样了:

[{
    "operation": "shift",
    "spec": {
      "events": {
        "*": {
          "recipientId": "events[&1].recipientIds"
        }
      }
    }
}]

1 个答案:

答案 0 :(得分:1)

规格

[{
  "operation": "shift",
  "spec": {
    "events": {
      "*": {
        "recipientId": "events[&1].recipientIds",
        //
        // go back up to the root of the tree, and then 
        //  come back down the key "networkResponseTime", and
        //  send it's value to "events[&1].networkResponseTime"
        "@(2,networkResponseTime)": "events[&1].networkResponseTime"
      }
    }
  }
}]