Skip to content

Commit

Permalink
let Mojo::JSON generate canonical JSON objects again (closes #665)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 1, 2016
1 parent 68d434c commit 5f47058
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

6.58 2016-03-31
6.58 2016-04-02
- Added fork policy to Mojolicious::Guides::Contributing.
- Improved Mojo::JSON to generate canonical JSON objects.

6.57 2016-03-23
- Fixed a few validation bugs in Mojolicious::Validator::Validation.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -213,7 +213,7 @@ sub _encode_array {
sub _encode_object {
my $object = shift;
my @pairs = map { _encode_string($_) . ':' . _encode_value($object->{$_}) }
keys %$object;
sort keys %$object;
return '{' . join(',', @pairs) . '}';
}

Expand Down
3 changes: 3 additions & 0 deletions t/mojo/json.t
Expand Up @@ -168,6 +168,9 @@ $bytes = encode_json {foo => []};
is $bytes, '{"foo":[]}', 'encode {foo => []}';
$bytes = encode_json {foo => ['bar']};
is $bytes, '{"foo":["bar"]}', 'encode {foo => [\'bar\']}';
$bytes = encode_json {foo => 'bar', baz => 'yada'};
is $bytes, '{"baz":"yada","foo":"bar"}',
'encode {foo => \'bar\', baz => \'yada\'}';

# Encode name
$bytes = encode_json [Mojo::JSON->true];
Expand Down

0 comments on commit 5f47058

Please sign in to comment.