Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Jolt json transformation, is it possible to copy a value into two different attributes?

Tags:

json

jolt

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 Jolf transformation?

like image 267
Sammy Avatar asked Jan 12 '17 16:01

Sammy


1 Answers

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.

like image 182
Milo S Avatar answered Oct 25 '22 08:10

Milo S