Skip to content

Instantly share code, notes, and snippets.

@yakovsh
Last active March 14, 2024 10:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakovsh/57726a6b96afaa7de95a to your computer and use it in GitHub Desktop.
Save yakovsh/57726a6b96afaa7de95a to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment