perl - How to enable "pretty" JSON rendering in Mojolicious::Lite? -
simple question. how turn on "pretty" json rendering in mojolicious::lite? i'm developing restful api , see output in bit more human readable format.
you override default json renderer in startup method.
for minimal example:
use json::xs; our $json = json::xs->new->utf8->pretty; sub startup { $self = shift; ... $self->app->renderer->add_handler(json => sub { ${$_[2]} = $json->encode($_[3]{json}); }); }
the default handler defined in mojolicious/renderer.pm , use mojo::json::encode_json
.
Comments
Post a Comment