โ12-09-2022 04:22 AM
Below is the Input
[
{
โ@idโ: โ2โ,
โcolโ: [
{
โ@idโ: โ2โ,
โ@transableโ: โyesโ,
โ$โ: โReplace1โ
},
{
โ@idโ: โ3โ,
โ@transableโ: โnoโ,
โ$โ: โReplace2โ
}
],
โgroupโ: [
{
โAโ: โA1โ,
โBโ: โB1โ,
โCโ: โC1โ,
โDโ: โD1โ,
โEโ: "E1 ",
โFโ: โF1โ,
โGโ: โG1โ,
โHโ: โโ,
โIโ: โโ
},
{
โAโ: โA2โ,
โBโ: โB2โ,
โCโ: โC2โ,
โDโ: โD2โ,
โEโ: โโ,
โFโ: โF2โ,
โGโ: โG2โ,
โHโ: โโ,
โIโ: โโ
}
]
}
]
expected Output :
[
{
"group": [
{
"A": "A1",
"B": "B1",
"C": "C1",
"D": "D1",
"E": "E1 ",
"F": "F1",
"G": "G1",
"H": "",
"I": ""
},
{
"A": "A2",
"B": "Replace1",
"C": "Replace2",
"D": "D2",
"E": "",
"F": "F2",
"G": "G2",
"H": "",
"I": ""
}
]
}
]
explanantion : @id refers to row number of the group and @id under col refers to the column number of the group where replacement needs to be done with the value of "$"
โ12-12-2022 06:16 PM
My bad, I got the charCode wrong it should be 64 ๐
$group.map((g,i)=> $row.find((a,b,c)=> a[โ@idโ] == i + 1) instanceof Object ? g.mapValues((val,key)=> $row.find((a,b,c)=> a[โ@idโ] == i + 1)[โcolโ].find((x,y,z)=> x[โ@idโ] == (key.charCodeAt(0) - 64)) instanceof Object ? $row.find((a,b,c)=> a[โ@idโ] == i + 1)[โcolโ].find((x,y,z)=> x[โ@idโ] == (key.charCodeAt(0) - 64))[โ$โ] : val ) : g )
โ12-12-2022 06:28 PM
hi @alchemiz the column keys in group array maynot be characters like A,B,Cโฆ its suppose to map based on the position like col1,col2 etc the expression suggested by @bojanvelevski
$group.map((x,index)=>$[โ@idโ] == index + 1 ? (x.mapValues((v,k)=> $col.find(e => e[โ@idโ]-1 == x.keys().indexOf(k)) != null ? $col.find(e => e[โ@idโ]-1 == x.keys().indexOf(k) ).get(โ$โ) : v)) : x)
works irrespective of column name in group array but its should be tweaked to satisfy my input becoz in which he had metioned $[โ@idโ] comes in as filed but in my case it comes in as an array element like this jsonPath($, โrow[][โ@idโ]") and also $col comes in as an array but in my case it comes in under row array like this jsonPath($, "row[].colโ), so i need help in adjusting the above expression to satisfy my input.Please could u help ๐
โ12-12-2022 06:42 PM
Just replace the criteria when checking for the col objectโฆ
$group.map((g,i)=> $row.find((a,b,c)=> a[โ@idโ] == i + 1) instanceof Object ? g.mapValues((val,key)=> $row.find((a,b,c)=> a[โ@idโ] == i + 1)[โcolโ].find((x,y,z)=> x[โ@idโ] == (g.keys().indexOf(key) + 1)) instanceof Object ? $row.find((a,b,c)=> a[โ@idโ] == i + 1)[โcolโ].find((x,y,z)=> x[โ@idโ] == (g.keys().indexOf(key) + 1)).get(โ$โ,val) : val ) : g )
โ12-12-2022 11:19 PM
@alchemiz thanks a lot!! its working ๐
โ12-19-2022 07:25 PM
Glad to be of help ๐ค