diff --git a/PBot/DualIndexHashObject.pm b/PBot/DualIndexHashObject.pm index 38de31ad..22764bf8 100644 --- a/PBot/DualIndexHashObject.pm +++ b/PBot/DualIndexHashObject.pm @@ -95,7 +95,7 @@ sub save { $self->{pbot}->{logger}->log("Saving $self->{name} to $filename\n"); my $json = JSON->new; - my $json_text = $json->pretty->utf8->encode($self->{hash}); + my $json_text = $json->pretty->canonical->utf8->encode($self->{hash}); open(FILE, "> $filename") or die "Couldn't open $filename: $!\n"; print FILE "$json_text\n"; diff --git a/PBot/HashObject.pm b/PBot/HashObject.pm index b418fde6..f179b66b 100644 --- a/PBot/HashObject.pm +++ b/PBot/HashObject.pm @@ -95,7 +95,7 @@ sub save { $self->{pbot}->{logger}->log("Saving $self->{name} to $filename\n"); my $json = JSON->new; - my $json_text = $json->pretty->utf8->encode($self->{hash}); + my $json_text = $json->pretty->canonical->utf8->encode($self->{hash}); open(FILE, "> $filename") or die "Couldn't open $filename: $!\n"; print FILE "$json_text\n"; diff --git a/PBot/Plugins/Spinach.pm b/PBot/Plugins/Spinach.pm index 0b9b6172..44e74ae4 100644 --- a/PBot/Plugins/Spinach.pm +++ b/PBot/Plugins/Spinach.pm @@ -162,13 +162,14 @@ sub load_questions { sub save_questions { my $self = shift; - my $json = encode_json $self->{questions}; + my $json = JSON->new; + my $json_text = $json->pretty->canonical->utf8->encode($self->{questions}); my $filename = exists $self->{loaded_filename} ? $self->{loaded_filename} : $self->{questions_filename}; open my $fh, '>', $filename or do { $self->{pbot}->{logger}->log("Failed to open Spinach file $filename: $!\n"); return; }; - print $fh "$json\n"; + print $fh "$json_text\n"; close $fh; } @@ -394,18 +395,7 @@ sub spinach_cmd { } $question->{$key} = $value; - - my $json = encode_json $self->{questions}; - my $filename = exists $self->{loaded_filename} ? $self->{loaded_filename} : $self->{questions_filename}; - open my $fh, '>', $filename or do { - $self->{pbot}->{logger}->log("Failed to open Spinach file $filename: $!\n"); - return; - }; - print $fh "$json\n"; - close $fh; - - $self->load_questions; - + $self->save_questions; return "$nick: Question $id: $key set to $value"; }