class JSONUtils {

    public static JsonNode filterJsonNodeForPath(JsonNode jsonNode, String filterPath) {
        ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());

        if(filterPath == null)
            return jsonNode;
        else if(jsonNode == null)
            return null;

        String key = getFirstJsonKeyForPath(filterPath);
        JsonNode newNode = null;

        if(key.contains("*")) {                                                         //ArrayNode
            newNode = objectMapper.createArrayNode();
            ArrayNode arrayNode = (ArrayNode) jsonNode;
            for(JsonNode value : arrayNode) {
                ((ArrayNode) newNode).add(filterJsonNodeForPath(value, getRemainingJsonKeyForPath(filterPath)));
            }
        } else {                                                                        //ObjectNode
            newNode = objectMapper.createObjectNode();
            ObjectNode objectNode = (ObjectNode) jsonNode;
            JsonNode value = objectNode.get(key);
            ((ObjectNode) newNode).set(key, filterJsonNodeForPath(value, getRemainingJsonKeyForPath(filterPath)));
        }

        return newNode;
    }

}