How to convert xml to json in c#?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.