'Merge json in nifi with JoltTransform
I would like to merge two different json in nifi. first json comes from an attribute to json processor and contains just an id, something like:
{
"id": "1234"
}
second one is a json of this structure:
[
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"}
]
desired result should be something like:
{
"id": "1234",
"data": [
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"},
{"id1": "1234","id2": "1234","id3": "1234"}
]
}
how can I make it? I was trying merge content to concatenate those two json flowfiles having this result:
[
{
"id": "1233"
},
[
{
"id1": "1234",
"id2": "1234",
"id3": "1234"
},
{
"id1": "1234",
"id2": "1234",
"id3": "1234"
},
{
"id1": "1234",
"id2": "1234",
"id3": "1234"
},
{
"id1": "1234",
"id2": "1234",
"id3": "1234"
}
]
]
now, I think I need a Jolt transform but I don't know which are the parameters of the transformation...
Solution 1:[1]
You have to choose transformation type Chain with your JOLT specification and it will work
Solution 2:[2]
I found out this solution but when I apply it on nifi it returns an error saying " is invalid because specification not valid for the selected transformation
but it works on jolttransformation demo (https://jolt-demo.appspot.com/#inception):
[
{
"operation": "shift",
"spec": {
"*": {
"id": "&",
"*": "result"
}
}
]
I don't understand why
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | it_is_vad |
Solution 2 | Barbaros Özhan |