Created
September 25, 2021 01:38
-
-
Save swhume/61cf2e117bbeac72dd32033f677e5199 to your computer and use it in GitHub Desktop.
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
package json2xml; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import org.json.XML; | |
/** | |
* | |
* @author Sam Hume shume@cdisc.org | |
*/ | |
public class Json2xml { | |
/** | |
* @param args the file name with path of the JSON file | |
*/ | |
public static void main(String[] args) throws IOException, JSONException { | |
if (args.length > 0) { | |
String filename = args[0]; | |
JSONObject json = parseJSONFile(filename); | |
String xml = XML.toString(json); | |
System.out.println("<share>" + xml + "</share>"); | |
} else { | |
System.out.println("Usage: json file name with full path must be included as a command-line argument"); | |
} | |
} | |
public static JSONObject parseJSONFile(String filename) throws JSONException, IOException { | |
String content = new String(Files.readAllBytes(Paths.get(filename))); | |
return new JSONObject(content); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment