Last active
December 19, 2015 01:18
-
-
Save jsianes/5874455 to your computer and use it in GitHub Desktop.
A short Java program that takes any XML file from input and generates a JSON compliant document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import org.json.*; | |
/* | |
JSON library provided by json.org (http://www.json.org/) | |
*/ | |
public class XmltoJson { | |
public static void main(String[] args) { | |
int i=0,size=args.length; | |
try { | |
while (i<size) { | |
String XMLString=""; | |
XMLString = new Scanner( new File(args[i]),"UTF-8").useDelimiter("\\A").next(); | |
JSONObject jsonObj = null; | |
jsonObj = XML.toJSONObject(XMLString); | |
String json = jsonObj.toString(); | |
if (!json.equals("{}")) { System.out.println(json); } | |
i++; | |
} | |
} catch (FileNotFoundException e) { | |
} catch (JSONException e) {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment