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

Report information
The Basics
Id:
117140
Status:
rejected
Priority:
Low/Low
Queue:

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

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Encoded JSON integers become strings
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 747
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.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 1314
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 }
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org> <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-27688-1471968707-751.117140-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 190
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...
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-27688-1471968707-751.117140-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org> <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org> <rt-4.0.18-27688-1471968707-751.117140-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-16737-1472004332-1044.117140-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 644
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?
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-16737-1472004332-1044.117140-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org> <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org> <rt-4.0.18-27688-1471968707-751.117140-0-0@rt.cpan.org> <rt-4.0.18-16737-1472004332-1044.117140-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-4988-1472497129-1230.117140-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 959
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.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-4988-1472497129-1230.117140-0-0@rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-338-1471896634-506.0-0-0@rt.cpan.org> <rt-4.0.18-27919-1471961435-1461.117140-0-0@rt.cpan.org> <rt-4.0.18-27688-1471968707-751.117140-0-0@rt.cpan.org> <rt-4.0.18-16737-1472004332-1044.117140-0-0@rt.cpan.org> <rt-4.0.18-4988-1472497129-1230.117140-0-0@rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-4988-1472497194-483.117140-0-0@rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 692
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 runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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