cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Json Array value to column formating

bill_sturdivant
New Contributor III

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โ€
}
]

2 REPLIES 2

tstack
Former Employee

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.)

This worked great! Thanks!