Quantcast
Channel: Perl XML::Twig send final output to JSON - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by simbabque for Perl XML::Twig send final output to JSON

$
0
0

XML::Twig has a simplify method that works similar to XML::Simple (which should not be used!). You could use that, but it's not very helpful for your example.

my $json = JSON->new->allow_nonref;my $pretty_printed = $json->pretty->encode( $twig->simplify );

This will output

"10.20.200.11"

That's valid JSON, but it's missing the Servers. I would expect something like

{ "Servers" => "10.20.200.11" }

In XML::Simple the KeepRoot option would do that, and XML::Twig's doc claims one should look at XML::Simple's docs for the options to simplify.

Return a data structure suspiciously similar to XML::Simple's. Options are identical to XMLin options, see XML::Simple doc for more details (or use DATA::dumper or YAML to dump the data structure)

However, it does not allow that option.


A better plan might be to write your own code to allow for a conversion based specifically on the format you want.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>