I want to use Perl script that gets the JSON data and converts it into XML file. How can I do that in Perl?
-
3json.org links to search.cpan.org/search?query=JSONJonas Elfström– Jonas Elfström2009-10-09 10:38:38 +00:00Commented Oct 9, 2009 at 10:38
-
1Don't put in jokey tags. It makes it a lot harder for people to find questions and answers.Alex Reynolds– Alex Reynolds2009-10-09 11:11:30 +00:00Commented Oct 9, 2009 at 11:11
-
3@Alex Reynolds: Some questions deserve answers and some do not. Specifically, send-me-teh-codez type questions do not. Sometimes, however, the question can be salvaged. In this case, after a second consideration, I decided to fix up the question. In the future, you may also want to fix the question as well as editing the tags. As for my attitude as to when a question should be fixed versus left to languish, see meta.stackexchange.com/questions/24838/…Sinan Ünür– Sinan Ünür2009-10-09 13:23:30 +00:00Commented Oct 9, 2009 at 13:23
Add a comment
|
2 Answers
use JSON;
my $json_string = '................';
my $deserialized = from_json( $json_string );
That's all - your JSON data is parsed and stored in $deserialized.
2 Comments
ysth
If performance is at all a concern, also install JSON::XS (JSON will use it if it's there...no code changes needed).
Well, sure it doesn't. There is no information how the xml should look (for example: what should be attribute, and what tag), so it's impossible to build xml out of data without schema specification. If schema is "any, just make it valid" -
use XML::Simple; print XMLout( $deserialized );Install: XML::XML2JSON with
sudo cpan XML::XML2JSON
and then try:
use XML::XML2JSON;
my $JSON = '{"entry":{"name":"Douglas Crockford","phone":"555 123 456"}}';
my $XML2JSON = XML::XML2JSON->new();
my $Obj = $XML2JSON->json2obj($JSON);
my $XML = $XML2JSON->obj2xml($Obj);
print $XML;