turn xml into json code example

Example: convert xml to json java

// gradle:
repositories {
    flatDir {
        dirs 'libs'
    }
}


dependencies {
    implementation name: 'json' // download here: https://search.maven.org/remotecontent?filepath=org/json/json/20210307/json-20210307.jar
	implementation 'com.github.javadev:underscore:1.66'
}
// kotlin
import org.json.*
import com.github.underscore.lodash.U

[...]

val jsonString: String = U.xmlToJson(xml)
val json: JSONObject = JSONObject(jsonString)
  
// java 
import org.json.*;
import com.github.underscore.lodash.U;

private string jsonString = U.xmlToJson(xml);
private JSONObject json = JSONObject(jsonString);