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;
 }
public class PersonDataFile extends DataFile {

  private String tempPersonCode;
  private DataFieldController dfc = new DataFieldController();
  private ArrayList<Object> person = dfc.getPersonList();
  private ArrayList<String> name = dfc.getNameList();
  private ArrayList<String> address = dfc.getAddressList();
  private ArrayList<String> emailAddresses = dfc.getEmailList();

  public PersonDataFile(String filePath) throws IOException {
    super(filePath);
    this.JSONName = "persons";
    this.finalJSON = this.convertToJSON(fileArray);
    this.finalJSONString = this.finalJSON.toString(2);
    this.outerJSONObject = jHandler.createJSONShell(this.JSONName, this.finalJSONString);
  }

  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;
  }
}