Skip Menu |

This queue is for tickets about the JSON CPAN distribution.

Report information
The Basics
Id: 25162
Status: resolved
Priority: 0/
Queue: JSON

People
Owner: Nobody in particular
Requestors: ddascalescu+perl [...] gmail.com
Cc:
AdminCc:

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



Subject: Preserve hash key order if Tie::IxHash is used
Hash keys are randomized even if the hash has been tied to 'Tie::IxHash'. Can this behavior be fixed so that hash keys are returned in order? In my application, I pass along things like column data, for which order is important. Hope that helps, Dan Dascalescu #! perl -w use strict; use Tie::IxHash; use JSON; $JSON::Pretty = 1; my %columns; tie %columns, 'Tie::IxHash'; %columns = ( id => 'int', field1 => 'String', field2 => 'String', field3 => 'String', field4 => 'String', field5 => 'String', ); my $js = objToJson(\%columns); print $js, "\n"; # randomized columns
From: ddascalescu+perl [...] gmail.com
Attached is a tentative patch for _hashToJson that ties the temporary %res variable to whatever the %$obj was tied to. This should probably be extended to arrayToJson and valueToJson. Hope that helps, Dan Vlad Dascalescu
--- C:\Perl\site\lib\JSON\Converter.pm 2/26/2007 18:40:23 +++ C:\prg\perl\test\Converter.pm 2/26/2007 18:39:48 @@ -99,102 +99,106 @@ my ($k,$v); my %res; + if (my $class = tied %$obj) { + $class =~ s/=.*//; + tie %res, $class; + } my ($pre,$post) = $self->_upIndent() if($JSON::Converter::pretty);
Thanks your report. Fixed version was released.