Created 03-11-2024 12:57 PM
Hi All,
I would like to replace first element of an array value i.e would like to replace with first net val with nifi attribute
input
{
"iH": [
{
"DN": "711449",
"iLineList": [
{
"DNnumber": "711449",
"DNLineNumber": 2
},
{
"DNNumber": "711449",
"DNLineNumber": 3
}
],
"netval": "22.09"
},
{
"DN": "711450",
"iLineList": [
{
"DNnumber": "711450",
"DNLineNumber": 2
},
{
"DNNumber": "711450",
"DNLineNumber": 3
}
],
"netval": "11.09"
}
]
}
defined SPEC like :
[
{
"operation": "shift",
"spec": {
"*": {
"0": {
"netVal": "iH[&1].netVal[0]",
"*": "iH[&1].&"
},
"*": "&1"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
// "invoiceHeader": {
"0": {
"netVal": "${netVal}"
}
// }
}
}
}
]
Expected output:
{
"iH" : [ {
"DN" : "711449",
"iLineList" : [ {
"DNnumber" : "711449",
"DNLineNumber" : 2
}, {
"DNNumber" : "711449",
"DNLineNumber" : 3
} ],
"netval" : "${netval}"
}, {
"DN" : "711450",
"iLineList" : [ {
"DNnumber" : "711450",
"DNLineNumber" : 2
}, {
"DNNumber" : "711450",
"DNLineNumber" : 3
} ],
"netval" : "11.09"
} ]
}
Created 03-11-2024 07:33 PM
Hi,
This is interesting . It looks trivial initially but its not that simple 🙂 It took me trial and error to get it to work using modify-overwrite-beta because the syntax is different from the shift spec where you reference array element at n index as "n" while in modify-overwrite-beta its "[0]" ! not sure why the difference. So this should work:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"iH": {
"[0]": {
"netval": "${netval}"
}
}
}
}
]
You can also do it using shift as follows:
[
{
"operation": "shift",
"spec": {
"*": {
"0": {
"netval": {
"#${netval}": "&3[&2].&1"
},
"*": "&2[&1].&"
},
"*": "&1[&]"
}
}
}
]
If that helps please accept solution.
Thanks
Created 03-11-2024 07:33 PM
Hi,
This is interesting . It looks trivial initially but its not that simple 🙂 It took me trial and error to get it to work using modify-overwrite-beta because the syntax is different from the shift spec where you reference array element at n index as "n" while in modify-overwrite-beta its "[0]" ! not sure why the difference. So this should work:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"iH": {
"[0]": {
"netval": "${netval}"
}
}
}
}
]
You can also do it using shift as follows:
[
{
"operation": "shift",
"spec": {
"*": {
"0": {
"netval": {
"#${netval}": "&3[&2].&1"
},
"*": "&2[&1].&"
},
"*": "&1[&]"
}
}
}
]
If that helps please accept solution.
Thanks
Created 03-12-2024 10:32 AM
Thanks a Lot the JOLT Master @SAMSAL , Modify-overwrite beta -logic worked perfectly.
but for Shift logic jolt demo throwing an execption Invalid reference key=#${netval} either blank or doesn't start with correct character=$
Created 03-13-2024 11:54 AM
@SAMSAL , After i added escaping to $ with double slash it got worked in shift too.
"#\\${netval}": "&3[&2].&1"
thanks a lot again