I am using org.json to convert an xml to json using below code snippet.Unfotunately, there is a structure called "countries" which is supposed to be an array, but can have only 1 country sometimes. In such cases, array is not getting disaplyed instead "countries" is showing up under {} instead of [{}] or [].
JSONObject xmlJSONObj = XML.toJSONObject(xsltresponse);
return xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
output i am getting is with after json conversion is:
{
"data":{
"name":"Microsoft",
"date":"today",
"countries":{
"name:"AN"
}}}
Instead of getting below output
{
"data":{
"name":"Microsoft",
"date":"today",
"countries":[{
"name:"AN"
}]
}}
How do i fix it?