If I have an external file containing this kind of information:
[code]
var Employees = [ // text file contents
“Lname,Fname,Age,Sex,Ext”, // description line
“Alley,Gasoline,75,M,x1234”,
“Boop,Betty,24,F,x2345”,
“Cow,Clarabel,35,F,x3456”,
“Duck,Daffy,58,M,x4567”,
“Fudd,Elmer,64,M,x5678”
];
I would like to transform this using JS into a json object with a format like this:
[code]
var jsonObj[“Lname,Fname”] = {‘Age’:’???’, ‘Sex’:’???’, ‘Ext’:’???’ }
How would I set the ‘Age’, ‘Sex’ and ‘Ext’ information for each employee?
(This assumes I am creating the jsonObj correctly [???])
Or should the transform be something like this?
[code]
jsonObject = {‘Names’:”, {‘Age’:”, ‘Sex’:”, ‘Ext’:” } }
jsonObj = new jsonObject;
// followed by some assignment to each field like
// jsonObj{Names.Emp[0]+’,’+Emp[1], {
// ‘Age’:Emp[2],’Sex’:Emp[3],’Ext’:Emp[4] } }
// after each ‘Employee’ element has been split to an array ‘Emp’
This json stuff intrigues me, but I’m having a tough time wrapping my head around it.
😮
Am I going in the right direction?
Is this possible using JS without retyping my initial database?