package eu.eudat.logic.utilities.json; import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class JsonSearcher { public static List findNodes(JsonNode root, String key, String value) { List nodes = new ArrayList<>(); for (Iterator it = root.elements(); it.hasNext(); ) { JsonNode node = it.next(); int found = 0; for (Iterator iter = node.fieldNames(); iter.hasNext(); ) { String fieldName = iter.next(); if (fieldName.equals(key)) { if (node.get(fieldName).asText().equals(value) || node.get(fieldName).asText().startsWith(value)) { nodes.add(node); found++; } } } if (found == 0) { nodes.addAll(findNodes(node, key, value)); } } return nodes; } }