Regression solution
You can use REGEX to remove any line from your data that binds "", [] or {} before you parse it with JSONParser.
A regular expression for something like this will look like. Keep in mind that you may have to configure a new line symbol depending on your OS.
[^\n]*(\"(\n)*\"|\[(\n)*\]|\{(\n)*\})[^\n]*
To account for the instance in which the JSON data looks like this
{ "models":{}, "path":[ { "path":"/web-profiles", "operations":[ { "nickname":"", "type":"", "responseMessages":[] } ] } ], "produces":[] }
The first time you run replaceAll, this will result in
{ "path":[ { "path":"/web-profiles", "operations":[ { } ] } ], }
Now we present an empty JSONObject inside the "operations" of a JSONArray. Therefore, this replaceAll function needs to be called again until the JSON String has any changes from the previous state.
Keep in mind that if you use functions like readLine () during data entry, it can remove the newline character, which will make this method inoperative. So decide that this will replace your read line with this.
json += in.readLine() + '\n';
Here is a brief program I wrote that actually removes empty json objects from the original string.
public static void main(String[] args){ // String from above example with newline characters intact String json = "{\n\"models\":{},\n\"path\":[\n{\n\"path\":\"/web-profiles\",\n\"operations\":[\n{\n\"nickname\":\"\",\n\"type\":\"\",\n\"responseMessages\":[]\n}\n]\n}\n],\n\"produces\":[]\n}"; // Value from the last iteration of the while loop String last = ""; // If there was no change from the last replaceAll call stop while( !last.equals(json) ){ last = json; // Same regex as above just escaped to work in a Java String json = json.replaceAll("[^\\n]*(\\{(\\n)*\\}|\\\"(\\n)*\\\"|\\[(\\n)*\\])[^\\n]*\\n",""); } System.out.println(json); }