Value_template: Sort JSON array

If the array is called value this will sort its items (ascending mode) using start as the key.

{{ value | sort(attribute='start') }}

Paste this into the Template Editor and experiment with it:

{% set value = [
   { 
      "allDay":true,
      "color":"brown",
      "start":"2019-08-08T00:00:00+02:00",
      "title":"P-K"
   },
   { 
      "allDay":true,
      "color":"grey",
      "start":"2019-08-09T00:00:00+02:00",
      "title":"Restafval"
   },
   { 
      "allDay":true,
      "color":"grey",
      "start":"2019-08-16T00:00:00+02:00",
      "title":"Restafval"
   },
   { 
      "allDay":true,
      "color":"blue",
      "start":"2019-08-21T00:00:00+02:00",
      "title":"PMD"
   },
   { 
      "allDay":true,
      "color":"grey",
      "start":"2019-08-23T00:00:00+02:00",
      "title":"Restafval"
   },
   { 
      "allDay":true,
      "color":"grey",
      "start":"2019-08-30T00:00:00+02:00",
      "title":"Restafval"
   },
   { 
      "allDay":true,
      "color":"grey",
      "start":"2019-01-04T00:00:00+01:00",
      "title":"Restafval"
   },
   { 
      "allDay":true,
      "color":"lightgreen",
      "start":"2019-01-04T00:00:00+01:00",
      "title":"Kerstboom"
   },
   { 
      "allDay":true,
      "color":"blue",
      "start":"2019-01-09T00:00:00+01:00",
      "title":"PMD"
   }
] %}

{{ value | sort(attribute='start') }}

1 Like