How to Create a subArray from an Array

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”
}
]
}

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:

2 Likes

Also, please always use a Preformatted Text block (with the </> icon) for any JSON blocks in your posts.