Forum Discussion

alex_panganiban's avatar
alex_panganiban
Contributor
3 years ago
Solved

Using sl.zipObject with Headerless CSV

Hoping someone might be able to find a solution to a challenge I have. I have a headerless csv file. I’m also reading in a header array that I wish to match up with the data in the headerless csv. I don’t want to add the header values to the CSV Parser snap so that I can avoid creating a custom parser for a multitude of headerless files that I might receive. Basically, here’s my situation.

“headers”: [“employeeId”, “firstName”, “lastName”]

The csv file looks like this after going through the CSV Parser.

“field1”: “1001”, “field2”: “Sylvester”, “field3”: “Stallone”
“field1”: “1005”, “field2”: “John”, “field3”: “Wick”
“field1”: “1010”, “field2”: “Arnold”, “field3”: “Schwarzenegger”

The results I desire should look like this:

“employeeId”: “1001”, “firstName”: “Sylvester”, “lastName”: “Stallone”
“employeeId”: “1005”, “firstName”: “John”, “lastName”: “Wick”
“employeeId”: “1010”, “firstName”: “Arnold”, “lastName”: “Schwarzenegger”

I’ve been playing around with sl.zipObject, but I can’t seem to make it work correctly. Hints, tips, and tricks would be greatly appreciated.

Thanks, Alex

  • I got my solution! @Spiro_Taleski, thank you so much for your wisdom! This is what Spiro showed me.

    I applied his solution to the bigger challenge I was having and this sample pipeline does exactly what I needed it to do.

    sample_ConfiguredHeadersToData_2022_11_23.slp (8.0 KB)

    Thank you all!

    Alex