Number problems with JSON, Perl and DBD::Oracle

I’m developing a little Oracle reporting tool using Perl Dancer and Google Charts and I’ve hit an issue with JSON::XS output of number columns being quoted. Here’s a small example of the problem with the solution I found.

And now if we run this we get the number 1 with quotes – “1”. Thats not what we want and is causing issues rendering the Google chart.

After a little bit of research the problem seems to stem from the JSON:XS module trying to guess the datatype while the DBD::oracle module binds each column as string by default. So there are potentially two solutions. Do the +0 trick on the scalar to convert to integer or use the features of the DBD::Oracle module to bind columns as type SQL_INTEGER.

I’ll take the second options and here’s what it looks like now.

Now when we run it our json output looks a lot better with the number 1 not quoted.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload CAPTCHA.