StackOverflow Answer: How to create row for Google's calendar graph api from JSON Object

Answer to question posted here: https://stackoverflow.com/questions/46483626/how-to-create-row-for-googles-calendar-graph-api-from-json-object

by Josh Parkinson

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

//Store processed rows in this array
$rows = [];

//Sample json data structure (pull yours from the source)
$jsonData = [
    {
    today_date: "2017-09-19",
    hours: "9"
  },
  {
    today_date: "2017-09-20",
    hours: "9"
  },
];

//Loop over every object within the json data, parsing the date string and
//creating a date object from it.
//Add the date object and the hours field to the rows array
$jsonData.forEach(function($data){
    $dateElements = $data.today_date.split("-");
    $rows.push([
      new Date($dateElements[0], $dateElements[1], $dateElements[2]),
      $data.hours
  ]);
});

console.log($rows)