How to format array elements during json to xml convertion using json-lib?
I found no solution using json-lib
You can get your expected result easily by using the library from json.org intead.
Here is the maven dependency if you want
<dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20140107</version></dependency>
Here is the code that I used to get the result:
import org.json.JSONObject;import org.json.XML; String jsonString = "{ \"tms:getTaskListResponse\": { \"tms:task\": [ { \"tms:creationDate\": \"2013-05-06T12:02:21.530+05:30\", \"tms:instanceId\": \"403\" }, { \"tms:creationDate\": \"2013-05-06T12:04:50.730+05:30\", \"tms:instanceId\": \"1224\" } ] }}"; JSONObject json = new JSONObject(jsonString); String xmlResponse = XML.toString(json); System.out.println(xmlResponse);