Piotr Dobrogost
Piotr Dobrogost

Reputation: 42435

Is there a way to force quotation of numbers in JSON 1.x Perl module?

Test script

use JSON;
$\ = "\n";
my $big_number = '12345678901234567890123456';
print $big_number;
print objToJson([$big_number]);

Output (JSON 1.07, Perl 5.8.7)

12345678901234567890123456
[12345678901234567890123456]

Output (JSON 2.15, Perl 5.10.1)

12345678901234567890123456
["12345678901234567890123456"]

I'd like to have strings representing numbers being quoted when using JSON 1.x the same way they are being quoted when using JSON 2.x. Is there any way to direct JSON 1.x Perl module to do this?

Upvotes: 2

Views: 219

Answers (1)

Michał Wojciechowski
Michał Wojciechowski

Reputation: 2490

Set AUTOCONVERT to a false value, i.e.:

$JSON::AUTOCONVERT = 0;

Upvotes: 6

Related Questions