Subject: | Invalid JSON output when date objects are used |
It the DataTable contains date or datetime objects invalid JSON is
generated by Data::Google::Visualization::DataTable
To see an example of this run the attached script.
Expected Result:
JSON parsed
Actual Result:
$ ./Google_data_table_date_test.pm
Error parsing JSON:
'null' expected, at character offset 132 (before "new Date( 2010, 9,
1...") at ./Google_data_table_date_test.pm line 32.
Note this JSON output is also rejected by http://www.jslint.com/
Subject: | Google_data_table_date_test.pm |
#!/usr/bin/perl -w
use Data::Google::Visualization::DataTable;
use DateTime;
use JSON::XS;
use strict;
my $datatable = Data::Google::Visualization::DataTable->new();
$datatable->add_columns(
{ id => 'date', label => "A Date", type => 'date', p => {} },
{ id => 'number', label => "Number", type => 'number' },
);
my $date = DateTime->new(
year => 2010,
month => 10,
day => 16
);
$datatable->add_rows(
{
date => $date,
number => 100,
}
);
my $output = $datatable->output_json();
#print "$output\n";
eval { my $json_ref = decode_json( $output ); };
if ( $@ )
{
print "Error parsing JSON:\n$@ \n";
}
else
{
print "JSON parsed\n";
}