public void transformToJson(List<YoutubeDescription> videos, String outputPath) { String json = null; try { Writer write = new FileWriter(new File(outputPath)); JSONArray videosArray = new JSONArray(); for (YoutubeDescription video : videos) { JSONObject jsonVideo = new JSONObject(); jsonVideo.put("title", video.getTitle()); jsonVideo.put("description", video.getDescription()); jsonVideo.put("categories", video.getCategories()); jsonVideo.put("tags", video.getTags()); videosArray.put(jsonVideo); } write.append(videosArray.toString()); write.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }