Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 07-31-2023 01:13 PM
I am a newbie to Nifi Jolt transform. I've been looking through the document, but still cannot figure out how to do mutiple headings for one array.
input json
{
"dataPackage": {
"datatest": {
"field": [
{
"Name": "test1",
"content": 45
},
{
"Name": "test2",
"content": 20
},
{
"Name": "test3",
"content": 23
}
]
}
}
}
Jolt Spec
[
{
"operation": "shift",
"spec": {
"dataPackage": {
"datatest": {
"field": {
"*": {
"Name": {
"test1": {
"#test1": "field[&3].Name",
"@(2,content)": "field[&3].content"
},
"test2": {
"#test2": "field[&3].Name",
"@(2,content)": "field[&3].content"
},
"test3": {
"#test3": "field[&3].Name",
"@(2,content)": "field[&3].content"
}
}
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"field": {
"*": {
"@(0,content)": "firstDetails.@(1,Name)"
}
}
}
}
]
current output
{
"firstDetails" : {
"test1" : 45,
"test2" : 20,
"test3" : 23
}
}
Expected output
{
"firstDetails" : {
"test1" : 45,
"test2" : 20
},
"secondDetails" : {
"test3" : 23
}
}
can you please help
Created 07-31-2023 01:42 PM
Hi @nict ,
Not sure how you want to add your headings (firstDetails, secondDetails...etc.) specially secondDetails is not found anywhere in your jolt spec. If you are just looking to associate different records (test1, test2, test3...etc.) to different header based on the value of "Name" where you have to list each Name value explicitly, then something like this will work:
[
{
"operation": "shift",
"spec": {
"dataPackage": {
"datatest": {
"field": {
"*": {
"Name": {
"test1": {
"@(2,content)": "firstDetails.test1"
},
"test2": {
"@(2,content)": "firstDetails.test2"
},
"test3": {
"@(2,content)": "secondDetails.test3"
}
}
}
}
}
}
}
}
]You can add more values\header as needed. However, if you are looking to create header dynamically based on the Name values then you have to provide more info on how you would associate records with header.
If that helps please accept solution.
Thanks
Created 07-31-2023 01:42 PM
Hi @nict ,
Not sure how you want to add your headings (firstDetails, secondDetails...etc.) specially secondDetails is not found anywhere in your jolt spec. If you are just looking to associate different records (test1, test2, test3...etc.) to different header based on the value of "Name" where you have to list each Name value explicitly, then something like this will work:
[
{
"operation": "shift",
"spec": {
"dataPackage": {
"datatest": {
"field": {
"*": {
"Name": {
"test1": {
"@(2,content)": "firstDetails.test1"
},
"test2": {
"@(2,content)": "firstDetails.test2"
},
"test3": {
"@(2,content)": "secondDetails.test3"
}
}
}
}
}
}
}
}
]You can add more values\header as needed. However, if you are looking to create header dynamically based on the Name values then you have to provide more info on how you would associate records with header.
If that helps please accept solution.
Thanks