I have an XML-RPC response, but I'm struggling to return it as a JSON using Mojo::XMLRPC
. I appreciate your guidance.
use Mojolicious::Lite;
use Mojo::XMLRPC qw[decode_xmlrpc];
#use XMLRPC::Fast;
get '/' => sub {
my $c = shift;
my $xml = <<~'XML';
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>myarray</name>
<value>
<array>
<data>
<value>
<struct>
<member>
<name>bob</name>
<value>
<boolean>0</boolean>
</value>
</member>
<member>
<name>alice</name>
<value>
<i4>1</i4>
</value>
</member>
</struct>
</value>
</data>
</array>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>
XML
$c->render(json => decode_xmlrpc($xml));
};
app->start;
According to the documentation https://metacpan.org/pod/Mojo::XMLRPC the decode_xmlrpc()
and from_xmlrpc()
methods return a Mojo::XMLRPC::Message
object containing the result. Looking at that module's source code https://metacpan.org/release/JBERGER/Mojo-XMLRPC-0.06/source/lib/Mojo/XMLRPC/Message.pm shows that it has a parameters
method. So you could try the following:
$c->render(json => decode_xmlrpc($xml)->parameters);