Thank you, Jens, for your suggestion. It’s certainly a valid solution, however, based on the needs of our application architecture, it won’t really fit in with our design pattern. We are moving away from using customized mappings, and having everything configurable instead. For this reason, I was focused on the sl.zipObject method to automatically align our data with configured headers. Here’s an example.
Say we have 2 customers that send us employee headerless data (we actually have more, which makes it even more important to develop a non-customized strategy that works for every customer). We don’t enforce any strict schemas or column ordering on our customers, so they can send the data elements in any order.
For customer ABC, we have a header configuration of “[employeeId, firstName, lastName, hireDate].” ABC sends their data like this, with the CSV parser results afterwards:
“1001”, “Sylvester”, “Stallone”, “2001-08-21”
“1010”, “Nicole”, “Kidman”, “1997-05-18”
“field001”: “1001”, “field002”: “Sylvester”, “field003”: “Stallone”, “field004”: “2001-08-21”
“field001”: “1010”, “field002”: “Nicole”, “field003”: “Kidman”, “field004”: “1997-05-18”
For customer XYZ, we have a header configuration of “[DOB_Date, First_Name, ID, Last_Name].” XYZ sends their data like this, with the CSV parser results afterwards:
“1960-07-04”, “Bobby”, “99999”, “Fischer”
“2005-04-27”, “Billie Jean”, “88888”, “King”
“field001”: “1960-07-04”, “field002”: “Bobby”, “field003”: “99999”, “field004”: “Fischer”
“field001”: “2005-04-27”, “field002”: “Billie Jean”, “field003”: “88888”, “field004”: “King”
Without having a create a separate parser with embedded header names for each customer, and without having to use a custom mapper for each customer, this is what I want to achieve for each respective customer.
ABC:
“employeeId”: “1001”, “firstName”: “Sylvester”, “lastName”: “Stallone”, “hireDate”: “2001-08-21”
“employeeId”: “1010”, “firstName”: “Nicole”, “lastName”: “Kidman”, “hireDate”: “1997-05-18”
XYZ:
“DOB_Date”: “1960-07-04”, “First_Name”: “Bobby”, “ID”: “99999”, “Last_Name”: “Fischer”
“DOB_Date”: “2005-04-27”, “First_Name”: “Billie Jean”, “ID”": “88888”, “Last_Name”: “King”
I’ve had partial success using ideas derived from Transforming JSON Data and JSON returns Column Names separately from the Rows - #5 by Garrett and using the sl.zipObject method, however, after going through the parser, my data has the field001, field002, etc. key tags on them, which is where I’m running into a wall. I feel if I could create an array of values for each row of my data, without key tags on them, then this might be the solution I’m looking for.
If I could make my post parser data transform from this:
“field001”: “1960-07-04”, “field002”: “Bobby”, “field003”: “99999”, “field004”: “Fischer”
to this, I feel like I could achieve my goal, because once I have the data array, the sl.zipObject method should work exactly as it does in the links I referenced above.
[“1960-07-04”, “Bobby”, “99999”, “Fischer”]
Anyways, thanks again Jens. Even though yours wasn’t the exact solution I was looking for, I truly do appreciate your time and generosity in responding to my plea for help. 🙂
Alex