Converting JSON to XML with Perl

Recently I had to work with Google AJAX API data which returns in JSON. For my purposes, the data needed to be in XML. While there is a CPAN module called XML2JSON which is designed to do that, for some reason it chokes on my input. Instead, I adopted a much more simple technique from the Google::Data::JSON module as follows:

use JSON::Any;
use XML::Simple;

my $convertor = JSON::Any->new();
my $data = $convertor->decode($json);
my $xml = XMLout($data);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s