是否可以使用NIFI中的Jolt规范从单个JSON创建多个JSON对象



我有一个输入JSON:

{
"flu": "flu1",
"reportId": 11,
"Name":"Transform"
}

预期输出:

{
"flu": "flu1",
"reportId": 11,
"Name":"Transform",
"fullname":"flu1-11-Transform"
}
{
"type":"relationship",
"id":"flu1-11-Transform"
}

规格:

[{
"operation":"modify-default-beta",
"spec":{
"fullname": "=concat(@(1,flu),'-',@(1,reportId),'-',@(1,Name))"
}
}]

上面的规范适用于第一个JSON对象。是否可以创建两个JSON对象,如预期输出中所示?

使用JOLT只能输出一个顶级对象,但该对象可以是数组(您想要的输出不是有效的JSON(。如果你想要一个包含这些对象的两元素数组,你可以使用以下规范:

[{
"operation": "modify-default-beta",
"spec": {
"fullname": "=concat(@(1,flu),'-',@(1,reportId),'-',@(1,Name))"
}
},
{
"operation": "shift",
"spec": {
"*": "[0].&",
"@(1,fullname)": "[1].id",
"#relationship": "[1].type"
}
}]

如果您需要两个用空格分隔的JSON对象,由于您在本问题中标记了Apache NiFi,因此可以将JoltTransformRecord与Output Grouping属性设置为One Line Per Object的JsonRecordSetWriter一起使用。格式与上面的不完全相同(每个对象都在一行上(,但它将是两个用空格分隔的JSON对象(有些系统接受/期望这种格式(。

最新更新