Two more problems with Mojolicious

Andrey Zelenkov zelenkov at nginx.com
Mon Mar 4 19:02:07 UTC 2019


> On 4 Mar 2019, at 19:06, Александр Поволоцкий <tarkhil at over.ru> wrote:
> 
> My program outputs JSON. decode_json works fine with HTTP, to_json is required for PSGI.

[..]

Hi Alex,

I’ve tried to use encode_json and to_json and they both work fine.

For encode_json:

===
use Mojolicious::Lite;
use Mojo::JSON qw(decode_json encode_json to_json);

get '/' => sub {
  my $c = shift;
  $c->write(encode_json({test => 'Привет I ♥ Mojolicious!'}));
};

app->start;
===

I've got response:

===
HTTP/1.1 200 OK
Date: Mon, 04 Mar 2019 18:53:21 GMT
Server: Unit/1.8.0
Connection: close
Transfer-Encoding: chunked

2a
{"test":"Привет I ♥ Mojolicious!"}
0
===

and for to_json:

===
use Mojolicious::Lite;
use Mojo::JSON qw(decode_json encode_json to_json);

get '/' => sub {
  my $c = shift;
  $c->write(to_json({test => 'Привет I ♥ Mojolicious!'}));
};

app->start;
===

I've got response:

===
HTTP/1.1 200 OK
Date: Mon, 04 Mar 2019 18:54:24 GMT
Server: Unit/1.8.0
Connection: close
Transfer-Encoding: chunked

2a
{"test":"Привет I ♥ Mojolicious!"}
0
===


Could you please provide more information about
how you try to use to_json?

--
Andrey Zelenkov








More information about the unit mailing list