Skip to content

Instantly share code, notes, and snippets.

@jageshmaharjan
Last active December 18, 2018 15:45
Show Gist options
  • Save jageshmaharjan/fc7aca156e8d8ae3582f2d8feb5395b4 to your computer and use it in GitHub Desktop.
Save jageshmaharjan/fc7aca156e8d8ae3582f2d8feb5395b4 to your computer and use it in GitHub Desktop.
Parser
//AKMall Json parser extension
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
import java.util.ArrayList;
public class ClassicTechJsonReader {
public static void main(String[] args) throws IOException, ParseException {
ArrayList<JSONObject> arrayList = new ArrayList<>();
String fPath = "result.json";
File file = new File(fPath);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null){
String[] newLine = line.split("},");
for (int i =0; i< newLine.length; i++){
if (i == 0){
newLine[i] = newLine[i].substring(1);
}
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(newLine[i] +"}");
arrayList.add(jsonObject);
}
}
WriteToFile(arrayList);
}
private static void WriteToFile(ArrayList<JSONObject> arrayList) throws IOException {
FileWriter fw = new FileWriter("AKMallParsedJson.json",true);
for (int i=0; i< arrayList.size(); i++)
{
fw.write(String.valueOf(arrayList.get(i) + "\n"));
}
fw.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment