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

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.

Replies are listed 'Best First'.
Re^5: Need same JSON response from Mojo & CGI::App
by Anonymous Monk on Jan 04, 2017 at 11:32 UTC
    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.