hey I've json that look like this
news
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-12'
},
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-30'
}
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-30'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-17'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-05-30'
}
and I'd like to sort it by the 'publish_date' per 'years' and then per 'months' to be looking like this:
{
2014: [{
04: [{
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-12'
},
{
title: 'hello world',
body: 'bla bla bla',
publish_date: '2014-04-30'
}
}]
]}
2015: [{
02: [{
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-30'
},
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-02-17'
},
}],
05: [{
{
title: 'hello world 2',
body: 'bla bla bla',
publish_date: '2015-05-30'
}
]}
}]
}
so I found this sort JSON by date to sort my json by dates, and after that I got this http://lodash.com/docs#forEach to run over my main json but how do I "split" the date so I can make it done ? split it into years and then month ? and how do I "push" into my new sorted json ? how can I make sure to not miss any month in every year ? a direction or anyway to make it done would be awesome :)
thank you verymuch!