OK, that was much harder than expected but I do have a solution.
The approach I've taken is to ask for a custom datatype in the ajax request and then implement a custom converter.
First of all the format I'm using for dates in my json is now date("yyyy-mm-dd"), the original example would look like:
{
"columns": [
["date", "Date"],
["number", "active_users"],
],
"rows": [
["date(2012-09-28)", 120, 98, 60],
["date(2012-09-29)", 127, 107, 63]
]
}
I then register a converter to convert text to a custom datatype called json_with_dates. A regex is used to search for the date format and replace them with statements to create date objects. Eval is then used to construct the json.
jQuery.ajaxSetup({
converters: {
"text json_with_dates": function( text ) {
var with_dates = text.replace(/\"date\(([^)]*)\)\"/g, function(a, date){
var dateParts = date.split("-");
return "new Date(" + dateParts[0] + "," + dateParts[1] + "," + dateParts[2] + ")";
});
var converted = eval("(" + with_dates + ")");
return converted;
}
}
});
I then make the ajax request for the custom datatype:
$.ajax({
url: div.data('chart'),
dataType: 'json_with_dates',
success: function(data_including_dates){
console.log("win!");
}
});