File file = new File("path");
InputStream is;
if (file.exists()) {
is = new FileInputStream(file);
} else {
is = new ClassPathResource("path").getInputStream();
}
String jsonListFileStr = IOUtils.toString(is, StandardCharsets.UTF_8);
JSONArray objects = JSONObject.parseArray(jsonListFileStr);
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
if (i % 2 == 0) {
jsonObject.put("XXX", "1");
} else {
jsonObject.put("XXX", "2");
}
}
System.out.println(objects);