โ05-27-2021 06:48 AM
Hoping someone can help me out. I have a JSON array. Itโs an array of string values and itโs called, washCare. I want to give each value in the array a property name. How would I write the correct mapping to accomplish the following? I thought I could possibly use the map arrow function, but I couldnโt figure out the correct syntax for the expression.
Original Array Format:
โwashCareโ:
[ โMachine Wash, WARMโ, โHand Wash Onlyโ ]
Desired Result:
โwashCareโ:
[
{โinstructionโ: โMachine Wash, WARMโ},
{instruction": โHand Wash Onlyโ}
]
โ05-27-2021 08:44 AM
Well, I played around. Not the most elegant solution, but this is what I came up with. There has to be a better way, but this worked. If anyone has a better solution, Iโd love to see it. See my photo attachment.
โ05-27-2021 11:07 AM
Please check the attached solution:
Test_Community_2021_05_27.slp (4.7 KB)
Hope this will help !
Regards,
Spiro Taleski
โ05-27-2021 03:33 PM
YES! So much more elegant!! Thank you so much. This helps in a big way.
โ06-01-2021 04:59 PM
There is an experimental API here. Given one or more input documents and the same number of desired output documents, the API tries to generate an expression that does the desired transformation.
In this case, change the input to
[
{
"washCare": [
"Machine Wash, WARM",
"Hand Wash Only"
]
}
]
and output to
[
{
"washCare": [
{
"instruction": "Machine Wash, WARM"
},
{
"instruction": "Hand Wash Only"
}
]
}
]
and click on Synthesize. The generated result is
{ washCare: $.washCare.map(elem => { instruction: elem }) }
Note: This is experimental right now and works for limited inputs only