I need to parse large file with more than one JSON in it. I didn't find any way how to do it. File looks like a BSON for mongoDB. File example:
{"column" : value, "column_2" : value}
{"column" : valeu, "column_2" : value}
....
I need to parse large file with more than one JSON in it. I didn't find any way how to do it. File looks like a BSON for mongoDB. File example:
{"column" : value, "column_2" : value}
{"column" : valeu, "column_2" : value}
....
You will need to determine where one JSON begins and another ends within the file. If each JSON is on an individual line, then this is easy, if not: You can loop through looking for the opening and closing braces, locating the points between each JSON.
char[] characters;
int openBraceCount = 0;
ArrayList<Integer> breakPoints = new ArrayList<>();
for(int i = 0; i < characters.length; i++) {
if(characters[i] == '{') {
openBraceCount++;
} else if(characters[i] == '}') {
openBraceCount--;
if(openBraceCount == 0) {
breakPoints.add(i + 1);
}
}
}
You can then break the file apart at each break point, and pass the individual JSON's into whatever your favorite JSON library is.