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