in reply to Re^2: Need same JSON response from Mojo & CGI::App
in thread Need same JSON response from Mojo & CGI::App

my mistake, I get the following {"Hello":1}

Replies are listed 'Best First'.
Re^4: Need same JSON response from Mojo & CGI::App
by Corion (Patriarch) on Jan 04, 2017 at 11:31 UTC

    It seems that CGI::Application itself doesn't declare a ->json_body method, but judging from the error message you get, you need to configure the JSON generator of that module to allow non-reference things to be output as JSON (strings).

    The error message most likely comes from JSON::XS, so $whatever->json_generator->allow_nonref() maybe is the correct method call.

    Looking at JSON CGI::Application, I see CGI::Application::Plugin::JSON, which uses JSON::Any, which doesn't really have a way to specify configuration to whatever module it instantiates. There is a hint of setting $ENV{JSON_ANY_CONFIG} in the code, which might work for you, because the plugin itself does not provide any way to give it a preconfigured JSON encoder. Bad plugin.

      SO do you suggest I manually add a json header then simply return the string "Hello"?

        I don't know how/why adding a JSON header would change the response body you send, and I don't know where in my reply I suggested to use a header at all.

Re^4: Need same JSON response from Mojo & CGI::App
by Arunbear (Prior) on Jan 04, 2017 at 11:24 UTC
    How about
    $c->render( json => { 'Hello' => undef } );