6

Am trying something very simple with Jolt transformation but struggling to get it to work.

If I have an input like:

{
  "id": "54436001"
}

I want output to be:

{
  "mediaId" : "54436001",
  "events" : {
    "mediaId" : "54436001"
  }
}

Which is copying a value to two different attributes. I would be tempted to try spec like this to work, but obviously it doesn't because of duplicate key.

[
  {
    "operation": "shift",
    "spec": {
      "id": "mediaId",
      "id": "events.mediaId"
    }
  }
]

Is this possible with Jolt transformation ?

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Sammy
  • 151
  • 2
  • 6

2 Answers2

15

Yes

Spec

[
  {
    "operation": "shift",
    "spec": {
      "id": ["mediaId", "events.mediaId"]
    }
  }
]

The idea is if you want shift to write a value to two locations in the output, use an array on the right hand side of the spec.

Milo S
  • 4,466
  • 1
  • 19
  • 22
  • 2
    Is there any good jolt transformation tutorial you know? Most of the tutorial I found seems bit complex for a quick read. I using it along with Apache Nifi, which comes very handy, but am using a very light form of it. – Sammy Jan 13 '17 at 10:58
0

Yet, there are some other alternatives such as

[
  {
    "operation": "shift",
    "spec": {
      "id": "mediaId",
      "@id": "events.mediaId"
    }
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "id": "events.mediaId",
      "@0,id": "mediaId"
    }
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "mediaId",
        "@0": "events.mediaId"
      }
    }
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "mediaId",
          "@1": "events.mediaId"
        }
      }
    }
  }
]

all of them will return the same desired result

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55