I have some JSON with the following structure:
{\"source\":[ {\"name\":\"john\",\"age\":20}, {\"name\":\"michael\",\"age\":25},
mainJSON.getJSONArray("source") returns a JSONArray, hence you can remove the new JSONArray.
mainJSON.getJSONArray("source")
JSONArray
new JSONArray.
The JSONArray contructor with an object parameter expects it to be a Collection or Array (not JSONArray)
Try this:
JSONArray jsonMainArr = mainJSON.getJSONArray("source");