I was able to figure out a woking solution
public static List<Map<String, Object>> cleanJsonData(List<Map<String, Object>> parsedJsonChildData, List<Map<String, Object>> parsedXmlChildData) { List<Map<String, Object>> modifiedParsedJsonChildData = new ArrayList<>();
for (int i = 0; i < parsedJsonChildData.size(); i++) {
Map<String, Object> jsonItem = parsedJsonChildData.get(i);
Map<String, Object> xmlItem = parsedXmlChildData.get(i);
Map<String, Object> filteredItem = new HashMap<>();
for (Map.Entry<String, Object> entry : jsonItem.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if ((value != null && !value.toString().isEmpty()) || xmlItem.containsKey(key)) {
filteredItem.put(key, value);
}
}
modifiedParsedJsonChildData.add(filteredItem);
}
return modifiedParsedJsonChildData;
}