private String getJSON(AggregateDB agg_db, Integer newcid, String usr) {
    ArrayList<String> course = agg_db.getCourse(newcid);
    // each element of course is an ordered list of
    // {id,institution,name,num,year,term,by,on,domainId,creator_id}
    String output = "\n    {\n";
    output +=
        "      id: \""
            + course.get(0)
            + "\", institution: \""
            + course.get(1)
            + "\", name:\""
            + course.get(2)
            + "\", num:\""
            + course.get(3)
            + "\", created: { by: \""
            + course.get(4)
            + "\", on: \""
            + course.get(5)
            + "\" }, domainId: \""
            + course.get(6)
            + "\", groupCount: \""
            + course.get(7)
            + "\", isMy: "
            + (usr.equals(course.get(8)))
            + ", desc: \""
            + course.get(9)
            + "\", visible: \""
            + course.get(10)
            + "\", ";
    // fetch all resources of the course
    // each element of the resource is an ordered list of {id,name};
    ArrayList<ArrayList<String>> resourceList = agg_db.getResource(course.get(0));
    output += "\n      resources: [";
    for (ArrayList<String> resource : resourceList) {
      output +=
          "\n        { id: \""
              + resource.get(0)
              + "\", name: \""
              + resource.get(1)
              + "\", "
              + getJSONProviderIds(agg_db, resource.get(0))
              + " },";
    }
    if (resourceList.isEmpty() == false)
      output = output.substring(0, output.length() - 1); // ignoring the last comma
    output += "\n      ],";

    // fetch all unit in the course
    ArrayList<ArrayList<String>> unitList = agg_db.getUnits(course.get(0));
    // each unit element is an ordered list with {id,name}
    output += "\n      units: [";
    for (ArrayList<String> unit : unitList) {
      output +=
          "\n        { id: \""
              + unit.get(0)
              + "\", name: \""
              + unit.get(1)
              + "\", "
              + getJSONunitActivity(agg_db, unit.get(0))
              + " },";
    }
    if (unitList.isEmpty() == false)
      output = output.substring(0, output.length() - 1); // ignoring the last comma
    output += "\n      ]";

    output += "\n    }";
    return output;
  }