I have a json file that is not in the format like I expect it to be. When I convert this json file into a csv file using CDL, it is not in a proper format as I am converting the JSONObject to JSONArray.
I want to change the format of the JSON file so that I don't have to change the JSONObject to JSONArray.
Existing File format -
{"CampaignID":1,"Name":"Halloween Deals","Status":"Sent"}
{"CampaignID":2,"Name":"New Year Deals Campaign 2","Status":"Sent"}
How I want it to be
{"Campaigns":[{"CampaignID":1,"Name":"Halloween Deals","Status":"Sent"},
{"CampaignID":2,"Name":"New Year Deals Campaign 2","Status":"Sent"}]}
I am extracting a json file CamapignList.json which has a list of campaigns. The file contains the REST API link for each campaign details. So, I am looping through the url for the number of campaigns in CampaignList.json file and writing the details in another file CamapignDetail.json which is not in the correct format.
JSONObject jObj = new JSONObject(result);
JSONArray items = jObj.getJSONArray("Items");
for (int i=0; i<items.length(); i++)
{
JSONObject cObj = items.getJSONObject(i);
String campaign_url = "rest.xyz.com/v1/Campaigns/…;
System.out.println(camp_url);
HttpGet reqst = new HttpGet(camp_url);
HttpResponse res= client.execute(req);
BufferedReader rd = new BufferedReader (new InputStreamReader(resp.getEntity().getContent()));
PrintWriter wr = new PrintWriter(new FileWriter(camp_file, true));
wr.println(rd.readLine());
}