Is there a way to easily reorganize data without using complex for loops (perhaps with Underscore.js or refining the MySQL query)? I have data formatted like this:
[
{
"J_NUM": "BOAK-1212",
"X_DUE_DATE": "2012-06-20T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Mail List Due",
},
{
"J_NUM": "BOAK-1212",
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
},
{
"J_NUM": "JEFF-2000",
"X_DUE_DATE": "2012-06-11T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Client Final Approval",
},
{
"J_NUM": "JEFF-2000",
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
What is the best method to group/nest this data based on a specific parameter, such as J_NUM
? The desired output would be structured like this:
[
{
"J_NUM": "BOAK-1212",
"SCHEDULE_SERIES": [
{
"X_DUE_DATE": "2012-06-20T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Mail List Due",
},
{
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
},
{
"J_NUM": "JEFF-2000",
"SCHEDULE_SERIES": [
{
"X_DUE_DATE": "2012-06-11T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Client Final Approval",
},
{
"X_DUE_DATE": "2012-06-08T00:00:00.000Z",
"X_LEAD_TIME": 0,
"X_NAME": "Vendor Specs 2",
}
]
}
]