How can we write a MapReduce to convert XML files to JSON files?
-
-
Answer:
90% of the answer is the same as the answer to, "How can we write a Java program to convert XML files to JSON?" There is not one way to do it, or one thing that this means. But there are certainly straightforward ways to do something like that. Then it is only a matter of wrapping up whatever that Java code is in a Hadoop job with only a Mapper. You point it at your XML files on HDFS. There are details here, like: if you have lots (like millions) of small XML files, you probably need to marshal them as records in a large SequenceFile first or else the number of files will become the problem. Also, you could conceivably invoke simple Java code with something like Pig or Spark rather than bother with M/R. You can also use M/R Streaming to invoke anything you can invoke on the command line to do the conversion.
Sean Owen at Quora Visit the source
Other answers
Although as mentioned by Sean Owen there is many ways to achieve the conversion of XML to JSON but in general you can follow the below steps to achieve the same in mapreduce .Step 1: Writing an InputFormat to read entire xml tag as a record.Step 2: Writing a Mapper function receiving the xml tag as a record and you should be using any of the xml parser to parse the data from the xml record.Step 3: use org.json.JSONObject class and create the json object from parsed data and write that object as an output.
Brundesh
Related Q & A:
- How to convert XML files to PDF files?Best solution by Super User
- How can I parse a complex XML with PHP and CDATA?Best solution by Stack Overflow
- How can I write a good reference letter?Best solution by dailywritingtips.com
- How can I write a free verse poem?Best solution by wikihow.com
- How can I write a really good mode?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.