Member since
10-03-2022
1
Post
0
Kudos Received
0
Solutions
10-03-2022
03:12 PM
Having issues flattening the nested array in an array of objects back to its parent. Given this JSON : [
{
"id": "13",
"uom": "EA",
"name": "pOne",
"display_name": "displayOne",
"brand": "brandOne",
"categories": [
{
"level1": "cLevel1",
"level2": "cLevel2"
}
]
},
{
"id": "87",
"uom": "EA",
"name": "pTwo",
"display_name": "displayTwo",
"brand": "brandTwo",
"categories": [
{
"level1": "cLevel1",
"level2": "cLevel2"
}
]
}
] I want to transform to this: [ {
"pName" : "pOne",
"pBrand" : "brandOne",
"pVariant" : "displayOne",
"pSku" : "13-EA-000",
"categoryHierarchy" : "cLevel1/cLevel2"
}, {
"pName" : "pTwo",
"pBrand" : "brandTwo",
"pVariant" : "displayTwo",
"pSku" : "87-EA-000",
"categoryHierarchy" : "cLevel1/cLevel2"
} ] So far I have these specs: [
{
"operation": "modify-default-beta",
"spec": {
"*": {
"productSku": "=concat(@(1,id),'-', @(1,uom),'-000')",
"categories": {
"*": {
"category": "=concat(@(1,level1),'/', @(1,level2))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"name": "[&1].pName",
"brand": "[&1].pBrand",
"display_name": "[&1].pVariant",
"productSku": "[&1].pSku",
"categories": {
"*": {
"category": "[&1].categoryHierarchy"
}
}
}
}
}
] It is however putting ALL the category values into a single array in the first object in the list, rather than in each respective object: [ {
"pName" : "pOne",
"pBrand" : "brandOne",
"pVariant" : "displayOne",
"pSku" : "13-EA-000",
"categoryHierarchy" : [ "cLevel1/cLevel2", "cLevel1/cLevel2" ]
}, {
"pName" : "pTwo",
"pBrand" : "brandTwo",
"pVariant" : "displayTwo",
"pSku" : "87-EA-000"
} ] What Am I missing? Thank you 🙂
... View more
Labels:
- Labels:
-
Apache NiFi