Skip Menu |
 
rt.cpan.org will be shut down on March 1st, 2021.

This queue is for tickets about the JSON-Color CPAN distribution.

Report information
The Basics
Id: 117140
Status: rejected
Priority: 0/
Queue: JSON-Color

People
Owner: Nobody in particular
Requestors: DIGORY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Encoded JSON integers become strings
Download (untitled) / with headers
text/plain 747b
Tested with the following script which compares regular JSON to JSON::Color: ---- #!/bin/env perl use strict; use warnings; use JSON::MaybeXS qw(decode_json); use JSON::Color qw(encode_json); chomp( my $input = <STDIN> ); my $ref = decode_json( $input ); my $json = JSON::MaybeXS->new; print $json->pretty(1)->canonical(1)->encode( $ref ) . "\n"; print encode_json( $ref, { pretty => 1, sort_by => sub { $JSON::Color::a cmp $JSON::Color::b } } ) . "\n"; ---- Input: echo '{"subtotal":21.40,"quantity":2,"description":"Foo"}' | my-script Output: { "description" : "Foo", "quantity" : 2, "subtotal" : 21.4 } { "description": "Foo", "quantity": "2", "subtotal": "21.4" } first is regular JSON, second is JSON::Color.
Download (untitled) / with headers
text/plain 1.2k
On Mon, 22 Aug 2016 20:10:34 GMT, DIGORY wrote: Show quoted text
> Tested with the following script which compares regular JSON to > JSON::Color: > > ---- > > #!/bin/env perl > > use strict; > use warnings; > > use JSON::MaybeXS qw(decode_json); > use JSON::Color qw(encode_json); > > chomp( my $input = <STDIN> ); > > my $ref = decode_json( $input ); > > my $json = JSON::MaybeXS->new; > print $json->pretty(1)->canonical(1)->encode( $ref ) . "\n"; > > print encode_json( $ref, { pretty => 1, sort_by => sub { > $JSON::Color::a cmp $JSON::Color::b } } ) . "\n"; > > ---- > > Input: > > echo '{"subtotal":21.40,"quantity":2,"description":"Foo"}' | my-script > > > Output: > > { > "description" : "Foo", > "quantity" : 2, > "subtotal" : 21.4 > } > > { > "description": "Foo", > "quantity": "2", > "subtotal": "21.4" > } > > first is regular JSON, second is JSON::Color.
You need to install an optional prereq Scalar::Util::LooksLikeNumber. I'll add this to the module's FAQ. % pmversion Scalar::Util::LooksLikeNumber 1.39.2 % echo '{"subtotal":21.40,"quantity":2,"description":"Foo"}' | /tmp/my-script { "description" : "Foo", "quantity" : 2, "subtotal" : 21.4 } { "description": "Foo", "quantity": 2, "subtotal": 21.4 }
Download (untitled) / with headers
text/plain 190b
On 2016-08-23 07:10:35, PERLANCAR wrote: Show quoted text
> You need to install an optional prereq Scalar::Util::LooksLikeNumber.
... but Scalar::Util has a looks_like_number sub, and is already in core...
Download (untitled) / with headers
text/plain 644b
On Tue, 23 Aug 2016 16:11:47 GMT, ETHER wrote: Show quoted text
> On 2016-08-23 07:10:35, PERLANCAR wrote:
> > You need to install an optional prereq Scalar::Util::LooksLikeNumber.
> > ... but Scalar::Util has a looks_like_number sub, and is already in core...
And how would you suggest Scalar::Util 1.39+'s looks_like_number() help differrentiating stringy number and numeric number? % perl -MScalar::Util=looks_like_number -E'say $Scalar::Util::VERSION; say looks_like_number $_ for 1,"1"' 1.45 1 1 % perl -MScalar::Util::LooksLikeNumber=looks_like_number -E'say looks_like_number $_ for 1,"1"'4352 1 Or is there another core module alternative for this?
Download (untitled) / with headers
text/plain 959b
On 2016-08-23 19:05:32, PERLANCAR wrote: Show quoted text
> On Tue, 23 Aug 2016 16:11:47 GMT, ETHER wrote:
> > On 2016-08-23 07:10:35, PERLANCAR wrote:
> > > You need to install an optional prereq > > > Scalar::Util::LooksLikeNumber.
> > > > ... but Scalar::Util has a looks_like_number sub, and is already in > > core...
> > And how would you suggest Scalar::Util 1.39+'s looks_like_number() > help differrentiating stringy number and numeric number?
If that's what Scalar::Util::looks_like_number does, then it is both misnamed and misdocumented. What you really want to be looking at (for the purposes of JSON serialization) is the numeric value of the scalar, after checking isdual() on a copy (there are other mechanisms in XS as well of course). However, I expect all of this is wasted effort as it's surely safer to rewrite this module as a wrapper around an existing battle-tested JSON serializer such as Cpanel::JSON::XS, rather than attempting to reimplement it.
Download (untitled) / with headers
text/plain 692b
On 2016-08-29 11:58:49, ETHER wrote: Show quoted text
> On 2016-08-23 19:05:32, PERLANCAR wrote:
> > On Tue, 23 Aug 2016 16:11:47 GMT, ETHER wrote:
> > > On 2016-08-23 07:10:35, PERLANCAR wrote:
> > > > You need to install an optional prereq > > > > Scalar::Util::LooksLikeNumber.
> > > > > > ... but Scalar::Util has a looks_like_number sub, and is already in > > > core...
> > > > And how would you suggest Scalar::Util 1.39+'s looks_like_number() > > help differrentiating stringy number and numeric number?
> > If that's what Scalar::Util::looks_like_number does, then it is both > misnamed and misdocumented.
oops, I meant Scalar::Util::LooksLikeNumber there (the module, not the dual-lifed function).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.