private JSONArray convertToJSON(ArrayList<String[]> fileArray) { // loop over lines of file for (int counter = 1; counter <= this.numberOfRecords; counter++) { tokenArray = fileArray.get(counter); // creates new object for each entry JSONObject tempJObject = new JSONObject(); // loop over objects in person for (int count = 0; count < tokenArray.length; count++) { Object ob = person.get(count); tempValue = tokenArray[count]; if (!(ob instanceof ArrayList)) { tempPersonCode = tempValue; tempJObject.put(ob.toString(), tempValue); } else { JSONObject aTempJSONObject = new JSONObject(); if (ob == emailAddresses) { tempJObject.put("emails", dfc.parseEmail(tempValue)); } else if (ob == address) { tempJObject.put("address", dfc.parseAddress(tempValue, aTempJSONObject)); } else if (ob == name) { String[][] tempArray = dfc.parseName(tempValue); tempJObject.put(tempArray[0][0], tempArray[0][1]); tempJObject.put(tempArray[1][0], tempArray[1][1]); } else { System.out.println("This should not happen\nSomething is wrong"); } } } DataFieldController.addToPersonCodeMap(tempPersonCode, tempJObject); JSONArrayList.put(tempJObject); } return JSONArrayList; }