Mojo::JSON->true encoded as 1 instead of true

37 views
Skip to first unread message

Lachlan Deck

unread,
Sep 28, 2016, 3:31:56 AM9/28/16
to Mojolicious
Hi all,

I'm using Mojolicious as a mock server, and I can't seem to encode booleans as real booleans (i.e., true or false).

Mojo::JSON->true seems to be encoded as 1 instead of true, for example.

What might I be missing?


use Mojo::JSON qw(decode_json encode_json);
...

get '/foo' => sub {
  my $c = shift;
  my $data = encode_json {
    ...
    flag => Mojo::JSON->true
  };

  $c->render(text => 'foo', data => $data);
}

cheers,
Lachlan

Jan Henning Thorsen

unread,
Sep 28, 2016, 8:18:44 AM9/28/16
to Mojolicious
Hey,

I think your issue is elsewhere. That code should work as expected. You can also try it out with a one-liner:

    $ perl -le'use Mojo::JSON "encode_json"; print encode_json {flag => Mojo::JSON->true}'
    {"flag":true}

Paul Williams

unread,
Sep 28, 2016, 4:23:34 PM9/28/16
to Mojolicious
Howdy,

Maybe check you're running the latest version of everything. Similar to Jan, I'm getting the code working as expected.

Lachlan Deck

unread,
Sep 28, 2016, 4:30:36 PM9/28/16
to mojol...@googlegroups.com
Yeah, thank you both. It’s all good.

I was indeed tripping myself up serving up a cached tmp file instead which hadn’t been updated.

cheers,
Lachlan

--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/ML3KfoWCTPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages