diff --git a/modules/core/src/main/java/org/apache/synapse/mediators/elementary/Target.java b/modules/core/src/main/java/org/apache/synapse/mediators/elementary/Target.java index 1027629b42..b1b7ac4c54 100644 --- a/modules/core/src/main/java/org/apache/synapse/mediators/elementary/Target.java +++ b/modules/core/src/main/java/org/apache/synapse/mediators/elementary/Target.java @@ -527,9 +527,15 @@ private String removeJSONFromString(MessageContext synCtx, String inputString, S if (path.equals("$") || path.equals("$.")) { result = ""; } else { - DocumentContext doc = JsonPath.parse(result); - doc.delete(path); - result = doc.jsonString(); + Object list = JsonPath.compile(path).read(result); + if (!((JsonArray) list).isEmpty()) { + DocumentContext doc = JsonPath.parse(result); + doc.delete(path); + result = doc.jsonString(); + } else { + log.warn("No matching elements were found for the given JSONPath: " + path + ". Therefore, " + + "no elements were removed."); + } } } }