To reach your requirement your JSON object should like this
{
"A":[
{
"name":"aaa"
},
{
"name":"aba"
}
],
"B":[
{
"name":"bbb"
},
{
"name":"bba"
}
]
}
A pseudo implementation for above Object would look like this:
//Maint list object
JSONObject objMainList = new JSONObject();
//prepare item array for "A"
JSONArray arrForA = new JSONArray();
JSONObject itemA = new JSONObject();
itemA.put("name", "aaa");
arrForA.put(itemA);
//prepare item array for "B"
JSONArray arrForB = new JSONArray();
JSONObject itemB = new JSONObject();
itemB.put("name", "bbb");
arrForB.put(itemB);
//Finally add item arrays for "A" and "B" to main list with key
objMainList.put("A", arrForA);
objMainList.put("B", arrForB);
UPDATE : to check if "A" or "B".. is exists or not
if(objMainList.has("A")){
}