We have:
[ { "EventStartDate": "17/10/2008", "EventType": "Restricted", "Event": "My Forum", "SessionStartTime": "18:00", "City": "Ryazan", "TypeSession": "1on1", "RowCount": 0 }, { "EventStartDate": "17/10/2008", "EventType": "Restricted", "Event": "My Forum", "SessionStartTime": "15:10", "City": "London", "TypeSession": "3on1", "RowCount": 1 }, { "EventStartDate": "24/11/2008", "EventType": "Conference", "Event": "AAA Test Event", "SessionStartTime": "15:10", "City": "Paris", "TypeSession": "Meeting", "RowCount": 2 }, { "EventStartDate": "24/11/2008", "EventType": "Conference", "Event": "AAA Test Event", "SessionStartTime": "16:10", "City": "Moscow", "TypeSession": "Breakfast", "RowCount": 3 } ] It is necessary to group sessions by date, by event type, by event name.
The final JSON seems correctly compiled:
"17/10/2008": { "Restricted": { "My Forum": { "18:00": { "City": "Ryazan", "TypeSession": "1on1", "RowCount": 0 }, "15:10": { "City": "London", "TypeSession": "3on1", "RowCount": 1 } } } }, "24/11/2008": { "Conference": { "AAA Test Event": { "15:10": { "City": "Paris", "TypeSession": "Meeting", "RowCount": 2 }, "16:10": { "City": "Moscow", "TypeSession": "Breakfast", "RowCount": 3 } } } } } My script for looping through an array is incorrect.
<script> var arr2 = []; for (var i = 0; i < arr1.length; i++) { if (arr2[arr1[i].EventStartDate] && arr2[arr1[i].EventStartDate].EventStartDate) { for (n in arr1[i]) { if (n != 'EventStartDate') { arr2[arr1[i].EventStartDate][n] = (arr2[arr1[i].EventStartDate][n]) ? arr2[arr1[i].EventStartDate][n] + ";" + arr1[i][n] : arr1[i][n]; } } } else { arr2[arr1[i].EventStartDate] = arr1[i]; } } console.log('result', arr2); </script> but he does not what I expected, it seems to me that I am not going the right way, send me)