I am reading an excel file (.xlsx) into a json array and I am creating into a map because I want to apply validations to each of the column individually. I am able to access it using the column name like so, Excel file is :
column A, column B
value of Column A, value of column B
I am accessing it like this : payload map(item, index) -> "Column Name A" : item."Column Name A", "Column Name B" : item."Column Name B"
Where column A and B are the excel column header.
What I want to do is to create the same map but using the column index like
payload map(item, index) ->
item[0].key : item[0],
item[1].key : item[1]
So that I do not have to hard code the excel header name and I can rely on the index of the excel columns.
I have tried using pluck $$ to create a map of Keys but I cannot create a map of keys-value, I am not able to use item[0] as key in a map.
How can I achieve above without using excel column header name?
Expected output should be like this :
{
"Column A " : "value of Column A",
"Column B" : "value of Column B",
"Errors" : "Column A is not valid"
}
[{"col1": "val1.1", "col2": "val1.2"}, {"col1": "val2.1", "col2": "val2.2"}]
. If you want to get a specific item, you can simply use the index:payload[0]
will return{"col1": "val1.1", "col2": "val1.2"}
– olamiral