I have converted the following CSV file
Col1;Col2
1;b
2;d
2;e
3;e
2;zz
into the following [ ][ ]
(associate array)
[
["Col1","Col2"],
["1","b"],
["2","d"],
["2","e"],
["3","g"],
["2","zz"]
]
The other possibility is an array of the CSV lines where columns are mapped into an object using the spread operator, I picked up from many searches :). This approach would handle more columns naturally.
[
{0:"Col1", 1:"Col2"},
{0:"1", 1:"b"},
{0:"2", 1:"d"},
...
{0:"2", 1:"zz"},
]
However, I want to make the JSON "hierarchical" and handle repeating field values, here from the left column "Col1" in order to derive the following JSON
{
"1":["b"],
"2":["d","e","zz"],
"3":["g"]
}
How would you go about doing this?
Of course we could generalize the question for n-columns of data where we could have several columns with repeating values (left to right).
Most of my searches seem to hit on duplicate data removal which is not my case, I would like to factor out the repeating fields as shown. I could visualize an iterative method but I hope someone has a .map() perhaps? compact/elegant approach.
Thank you.