โ01-10-2018 07:52 AM
For the json below I need to be able to make the TabStatus.TabLabel value a column and TabStatus.TabValue as the value of that column and discard the rest of the data in the Array. Note that the TabStatus array can have up to 166 items where below I only show 2.
Input:
[{
โEnvelopeIDโ : โf76fa554-5bf3-44df-a992-1c04e6be5280โ,
โRecipientIdโ : โ22cca495-954e-4930-8070-3be40ada6105โ,
โTabStatusโ : [{
โTabTypeโ : โApproveโ,
โStatusโ : โActiveโ,
โXPositionโ : โ1025โ,
โYPositionโ : โ1500โ,
โTabLabelโ : โSCT Approveโ,
โTabNameโ : โSCT Approveโ,
โTabValueโ : โAโ,
โDocumentIDโ : โ1โ,
โPageNumberโ : โ2โ,
โOriginalValueโ : null
}, {
โTabTypeโ : โDeclineโ,
โStatusโ : โActiveโ,
โXPositionโ : โ1026โ,
โYPositionโ : โ1565โ,
โTabLabelโ : โSCT Declineโ,
โTabNameโ : โSCT Declineโ,
โTabValueโ : โNโ,
โDocumentIDโ : โ1โ,
โPageNumberโ : โ2โ,
โOriginalValueโ : null
}
]
}, {
โEnvelopeIDโ : โ18ea8193-085d-482a-bdac-a8024821c27cโ,
โRecipientIdโ : โ0f0962e2-32e4-4d7e-a520-71aa2366c3edโ,
โTabStatusโ : [{
โTabTypeโ : โApproveโ,
โStatusโ : โActiveโ,
โXPositionโ : โ1025โ,
โYPositionโ : โ1500โ,
โTabLabelโ : โSCT Approveโ,
โTabNameโ : โSCT Approveโ,
โTabValueโ : โNโ,
โDocumentIDโ : โ1โ,
โPageNumberโ : โ2โ,
โOriginalValueโ : null
}, {
โTabTypeโ : โDeclineโ,
โStatusโ : โActiveโ,
โXPositionโ : โ1026โ,
โYPositionโ : โ1565โ,
โTabLabelโ : โSCT Declineโ,
โTabNameโ : โSCT Declineโ,
โTabValueโ : โYโ,
โDocumentIDโ : โ1โ,
โPageNumberโ : โ2โ,
โOriginalValueโ : null
}
]
}
]
output:
[ {
โEnvelopeIDโ : โf76fa554-5bf3-44df-a992-1c04e6be5280โ,
โRecipientIdโ : โ22cca495-954e-4930-8070-3be40ada6105โ,
โSCT Approveโ : โAโ,
โSCT Declineโ : โNโ
}, {
โEnvelopeIDโ : โ18ea8193-085d-482a-bdac-a8024821c27cโ,
โRecipientIdโ : โ0f0962e2-32e4-4d7e-a520-71aa2366c3edโ,
โSCT Approveโ : โNโ,
โSCT Declineโ : โYโ
}
]
โ01-10-2018 10:05 AM
Youโre looking for the extend() method on objects. It will take an array of key/value pairs and return a new object consisting of the original object plus the properties from the array. But, first, we need to change the TabStatus array into pairs using the map() method, like so:
$TabStatus.map(x => [x.TabLabel, x.TabValue])
Putting it all together, you can use an object literal to create an object with the values you want to pass through and then call extend with the massaged TabStatus array:
{
EnvelopeID: $EnvelopeID,
RecipientId: $RecipientId
}.extend($.TabStatus.map(x => [x.TabLabel, x.TabValue]))[/code]
There are other ways to do this as well, you could call extend on the original document (e.g. $.extend(...)
). But, that would include the original TabStatus array in the output, so youโd have to use a separate mapper to delete that.
(Thanks for providing example output, makes things much easier.)
โ01-11-2018 06:13 AM
This worked great! Thanks!