Question
Please advise which direction to think.
There is a multidimensional array like this:
[
{
a = 12,
b = [1,2,3]
},
{
a = 25,
b = [8,2]
},
]
It needs to be transformed into:
[
{
a = 12,
b = 1
},
{
a = 12,
b = 2
},
{
a = 12,
b = 3
},
....
]
The idea of using two nested loops comes to mind, but then some variable is needed to accumulate the array values instead of overwriting them.
Or should the logic be completely different?
Answer
This is done like this:
= : listTrain(list: $replace)
replace: listReplace(list: #h_data; action: $new_val; value: "value")
new_val: rowListCreate(field: "a" = $#value[a]; field: "b" = $#value[b])
In h_data
are the original data. The result:
[
{
"a": "12",
"b": "1"
},
{
"a": "12",
"b": "2"
},
{
"a": "12",
"b": "3"
},
{
"a": "25",
"b": "8"
},
{
"a": "25",
"b": "2"
}
]