我有以下输入json:
输入
{
"temp": "1010328|1010329",
"data": [
{
"product": {
"items": [
{
"item_number": "1010328",
"attributes": [
{
"id": "myId01",
"type": "int"
}
]
},
{
"item_number": "1010329",
"attributes": [
{
"id": "myId02",
"type": "int"
}
]
},
{
"item_number": "1010330",
"attributes": [
{
"id": "myId03",
"type": "int"
}
]
}
]
}
}
]
}
在 items 数组中,应根据“temp”的值过滤项目:
期望的输出
{
"temp": "1010328|1010329",
"data": [
{
"product": {
"items": [
{
"item_number": "1010328",
"attributes": [
{
"id": "myId01",
"type": "int"
}
]
},
{
"item_number": "1010329",
"attributes": [
{
"id": "myId02",
"type": "int"
}
]
}
]
}
}
]
}
我尝试使用分配给 nifi 变量“temp”的字符串 1010328|1010329 在 jolt 中进行正常过滤。但显然,当涉及到“过滤任务”时,jolt 不接受变量的值。
任何帮助将不胜感激-
您可以从将
"temp"
属性转换为数组开始,在数组的索引下循环并重新构造回其原始结构,如以下转换所示:
[
{ //convert "temp" attribute to an array with the identical name
"operation": "modify-overwrite-beta",
"spec": {
"temp": "=split('\\|',@(1,&))"
}
},
{
"operation": "shift",
"spec": {
"temp": "&",
"data": {
"*": {
"product": {
"items": {
"*": {
"*": "@(1,item_number).&5.&4.&3.&2.&" //keep the all nestine key names
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"temp": {
"*": {
"*": {
"@(3,&)": ""
}
},
"@": "&" //keep the "temp" array
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"temp": "&",
"*": {
"*": {
"*": {
"*": "&3[&2].&1.&[]"
}
}
}
}
}
},
{ //convert "temp" back to an attribute
"operation": "modify-overwrite-beta",
"spec": {
"temp": "=join('|',@(1,&))"
}
}
]