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

不想你离开。 提交于 2020-05-29 10:22:45

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/41618761/with-jolt-json-transformation-is-it-possible-to-copy-a-value-into-two-different

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!