0

I am having troubles transforming JSON payload into the desired document.

I have following input:

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

Desired output:

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

How will the JOLT spec look like for this example?

So far I have smth like this:

[{
    "operation": "shift",
    "spec": {
      "events": {
        "*": {
          "recipientId": "events[&1].recipientIds"
        }
      }
    }
}]
Ihor M.
  • 2,728
  • 3
  • 44
  • 70

1 Answers1

1

Spec

[{
  "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"
      }
    }
  }
}]
Milo S
  • 4,466
  • 1
  • 19
  • 22