Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Jolt transformation Array to Flatten

avatar
Rising Star

Hi Jolt Experts,

Iam looking to use the Jolt transformation in NIFI and looking for a help.

{
"header": {
"timeStamp": "1681441547144",
"activityId": "5142917973836294867"
},
"resource": {
"drniId": "261968731599587823",
"@type": "Order",
"subtype": "Retail",
"name": "CCCCC",
"resourceCharacteristic": [
{
"propname": "aaa",
"value": "P_1655442"
},
{
"name": "latest",
"value": [
11,
200,
300,
16,
2,
3
]
}]
}
}

 

To have an output like

{
"records" : [ {
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"drniId" : "261968731599587823",
"type" : "Order",
"subtype" : "Retail",
"name" : "CCCCC",
"propname" : "aaa",
"value" : "P_1655442"

}, {
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"drniId" : "261968731599587823",
"type" : "Order",
"subtype" : "Retail",
"name" : "CCCCC",
"propname" : "latest",
"value" : "11,200,300,16,2,3"
} ]
}

 

Basically copying all the top header and resource into to new by flattening it. Any help appreciated.

 

 

2 ACCEPTED SOLUTIONS

avatar
Super Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar
Super Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
7 REPLIES 7

avatar
Super Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar
Rising Star

Thanks @SAMSAL .It worked. In the same way how do i get an simillar output for "resourceRelationshipCharacteristic" . i tried few option but not getting the desirable output.

 

{
"header": {
"version": "1.0",
"timeStamp": "1681441547144",
"activityId": "5142917973836294867",
"action": "modify"
},
"resource": {
"drniId": "261968731599587823",
"@type": "VVVVV",
"subtype": "BBBBBB",
"name": "VVVVVVV",
"resourceCharacteristic": [
{
"name": "matchingkey",
"value": "CCCCC",
"@type": "string"
}
],
"resourceRelationship": [
{
"drniId": "261968731599587635",
"@type": "CCCCCC",
"subtype": "OTU4",
"name": "BBBBBB",
"relationDrniId": "5143209344417655493",
"resourceRelationshipCharacteristic": [
{
"name": "p3Latest",
"value": true,
"@type": "boolean"
},
{
"name": "isNotInRoute",
"value": "N",
"@type": "string"
}
]
},
{
"drniId": "261988866406271344",
"@type": "BVDFDFS",
"subtype": "VDFDG",
"name": "ABCC",
"relationDrniId": "5143209344417655494",
"resourceRelationshipCharacteristic": [
{
"name": "p3Latest",
"value": true,
"@type": "boolean"
},
{
"name": "isNotInRoute",
"value": "N",
"@type": "string"
}
]
}
]
}
}

avatar
Super Guru

Hi ,

Can you provide the expected json output? The json you provided seems complex and nested. I'm not sure what exactly you are expecting.

avatar
Rising Star

Basically inhertied properties of header and resource inside resourceRelationshipCharacteristic

 

{
"records" : [ {
"relationDrniId" : "5143209344417655493",
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"action" : "modify",
"name": "p3Latest",
"value": true,
"@type": "boolean"

},

{
"relationDrniId" : "5143209344417655493",
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"action" : "modify",
"name": "isNotInRoute",
"value": "N",
"@type": "string"

} ,




{
"relationDrniId" : "5143209344417655494",
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"action" : "modify",
"name": "p3Latest",
"value": true,
"@type": "boolean"

} ,


"relationDrniId" : "5143209344417655494",
"timeStamp" : "1681441547144",
"activityId" : "5142917973836294867",
"action" : "modify",
"name": "isNotInRoute",
"value": "N",
"@type": "string"

}



]
}

avatar
Super Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar
Rising Star

Thanks @SAMSAL You are a genius. I was caught with the duplicate index array and couldn't resolve. 

avatar
Rising Star

I have used the below spec for moving some of the resource characterstic to top level but iam getting null values. 

[
{
"operation": "shift",
"spec": {
"header": {
"timeStamp": "records.inv_activity_ts",
"activityId": "records.inv_activity_id",
"action": "records.action"
},
"resource": {
"drniId": "records.inv_id",
"subtype": "records.inv_subtype",
"name": "records.inv_name",
"resourceCharacteristic": {
"*": {
"name": {
"matchingkey": "records.matchingkey-value",
"status": "records.status-value"
},
"value": {
"matchingkey": "records.matchingkey-value",
"status": "records.status-value"
}
}
}
}
}
}
]

 

Output iam getting

{
"records" : {
"inv_activity_ts" : "1670484663189",
"inv_activity_id" : "256388257993155783",
"action" : "create",
"inv_id" : "256383859946641699",
"inv_subtype" : "Backplane Connection",
"inv_name" : "Backplane Connection",
"matchingkey-value" : null,
"status-value" : null
}
}

 

What is mistake iam making?.