Commit be89a50a authored by Jean Vintache's avatar Jean Vintache

JsonToXml

parent 1755172d
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jsontoxml;
import java.io.File;
import java.io.FileNotFoundException;
import org.json.JSONObject;
import org.json.XML;
import java.util.Scanner;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JeanV
*/
public class JsonToXml {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// args[0] should hold a JSON file path.
if (args.length == 0) {
return;
}
try {
String jsonText = new Scanner(new File(args[0])).useDelimiter("\\Z").next();
JSONObject json = new JSONObject(jsonText);
String xml = XML.toString(json);
PrintWriter out = new PrintWriter("json_xml_out.xml");
out.println(xml);
out.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(JsonToXml.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment