Created
June 24, 2016 23:17
-
-
Save brianmed/3f3e47c1fb9dddd840f3f7e9a17cc53b to your computer and use it in GitHub Desktop.
Attempt at pretty printing JSON in a Mojolicious::Lite app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Tie::IxHash; | |
use JSON::XS; | |
use strict; | |
use warnings; | |
helper pretty_json => sub { | |
my ($self, $ref) = @_; | |
my $json = JSON::XS->new; | |
$json->pretty(1); | |
return $json->encode( $ref ); | |
}; | |
get '/' => sub { | |
my $c = shift; | |
tie(my %j, 'Tie::IxHash'); | |
$j{result} = { counter => "123" }; | |
$j{number} = { num => '55' }; | |
my $pretty_json = $c->pretty_json(\%j); | |
$c->render(text => $pretty_json); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment