02-05-2021 05:47 AM
Hi,
I want to create a 2 sub array from an Array.
Input :
{
“array1”:[
{
“Item”:“Pen”,
“Item Desc”:“Black”,
“Length”: “7”,
“Width”: “2”,
“Weight”:“5”
}
{
“Item”:“Pen”,
“Item Desc”:“Black”,
“Length”: “7”,
“Width”: “2”,
“Weight”:“5”
}
]
}
Output:
{
“Array1”:[
{
“Item”:“Pen”,
“Item Desc”:“Black”,
“Length”: “7”,
“Width”: “2”,
“Weight”:“5”
}
{
“Item”:“Pen”,
“Item Desc”:“Black”,
“Length”: “7”,
“Width”: “2”,
“Weight”:“5”
}
]
“Array2”:[
{
“Item”: “Pen”,
“Item Desc”:“Black”
},
{
“Item”:“Pen”
“Item Desc”:“Red”
}
]
}
02-05-2021 06:55 AM
Use a mapper, then
For the first array just write $array1 in the expression, and for the second you need this expression: $array1.map(val => {“Item”: val.Item, “Item Desc”: val[‘Item Desc’] })
Result:
02-05-2021 02:34 PM
Also, please always use a Preformatted Text block (with the </> icon) for any JSON blocks in your posts.