https://www.javatpoint.com/convert-xml-to-json-in-java
I got it from here.
package com.convertxml;
import org.json.*;
public class ConvertXML {
public static String xml= "<?xml version="1.0" ?><root><test attribute="text1">javatpoint</test><test attribute="text2">JTP</test></root>";
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
JSONObject json = XML.toJSONObject(xml);
String jsonString = json.toString(4);
System.out.println(jsonString);
}catch (JSONException e) {
// TODO: handle exception
System.out.println(e.toString());
}
}
}
www.javatpoint.com
Convert XML to JSON in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.