代码之家  ›  专栏  ›  技术社区  ›  Ihor M.

使用以下输入,JOLT规范将如何实现预期结果?

  •  0
  • Ihor M.  · 技术社区  · 7 年前

    我无法将JSON负载转换为所需的文档。

    我有以下输入:

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

    期望输出:

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

    到目前为止,我有这样的smth:

    [{
        "operation": "shift",
        "spec": {
          "events": {
            "*": {
              "recipientId": "events[&1].recipientIds"
            }
          }
        }
    }]
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Milo S    7 年前

    [{
      "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"
          }
        }
      }
    }]