使用 JoltTransform 在 nifi 中合并 json [英] Merge json in nifi with JoltTransform
问题描述
我想在 nifi 中合并两个不同的 json.第一个 json 来自 json 处理器的一个属性,并且只包含一个 id,例如:
<代码> {id":1234"}
第二个是这种结构的json:
<预><代码>[{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"}]想要的结果应该是这样的:
<代码>{id":1234",数据":[{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"},{id1":1234",id2":1234",id3":1234"}]}
我该怎么做?我正在尝试合并内容以连接这两个具有此结果的 json 流文件:
<预><代码>[{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"}]]现在,我想我需要一个 Jolt 转换,但我不知道哪些是转换的参数...
我发现了这个解决方案,但是当我将它应用到 nifi 时它返回一个错误说<强>"无效,因为规范对所选转换无效
但它适用于 jolttransformation 演示 (https://jolt-demo.appspot.com/#开始):
<预><代码>[{操作":移位",规格":{*":{id":id",*":结果"}}]我不明白为什么
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...
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": "id",
"*": "result"
}
}
]
I don't understand why
这篇关于使用 JoltTransform 在 nifi 中合并 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!