Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved Mojo::JSON to generate canonical JSON objects (closes #665)
  • Loading branch information
kraih committed Aug 5, 2014
1 parent 7039828 commit 122f380
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@
5.25 2014-08-05
- Added reduce method to Mojo::Collection.
- Improved sort method in Mojo::Collection to use $a and $b. (batman)
- Improved Mojo::JSON to generate canonical JSON objects.
- Improved documentation browser CSS.
- Fixed escaping bugs in Mojo::DOM::CSS.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -225,7 +225,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 @@ -165,6 +165,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 122f380

Please sign in to comment.