If you don't need recursive find, just use path or get methods?

Answer from StaxMan on Stack Overflow
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Method similar to findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for which isMissingNode() returns true; and all value access methods return empty or missing value. ... Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value) public abstract JsonNode findParent(String fieldName)
🌐
Red Hat
access.redhat.com › webassets › avalon › d › red-hat-jboss-enterprise-application-platform › 7.1.beta › javadocs › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (Red Hat JBoss Enterprise Application Platform 7.1.0.Beta1 public API)
Method similar to findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for which isMissingNode() returns true; and all value access methods return empty or missing value. ... Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value) public abstract JsonNode findParent(String fieldName)
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.jsonnode
com.fasterxml.jackson.databind.JsonNode.findValue java code examples | Tabnine
String code = jsonResp.findValuesAsText("code").get(0); if (code.equals("200")) { return jsonResp.findValue("text").get(0).asText(); } else { throw new TikaException(jsonResp.findValue("message").get(0).asText()); ... @Override public JsonNode findValue(String fieldName) { for (Map.Entry<String, JsonNode> entry : _children.entrySet()) { if (fieldName.equals(entry.getKey())) { return entry.getValue(); } JsonNode value = entry.getValue().findValue(fieldName); if (value != null) { return value; } } return null; }
🌐
Fasterxml
fasterxml.github.io › jackson-core › javadoc › 1.9 › org › codehaus › jackson › JsonNode.html
JsonNode (Jackson JSON Processor)
public final List<JsonNode> findValues(String fieldName) Method for finding JSON Object fields with specified name, and returning found ones as a List. Note that sub-tree search ends if a field is found, so possible children of result nodes are not included. If no matching fields are found ...
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 4229
`JsonNode.findValues()` and `findParents()` missing expected values in 2.16.0 · Issue #4229 · FasterXML/jackson-databind
November 28, 2023 - Search before asking I searched in the issues and found nothing similar. Describe the bug JsonNode.findValues and JsonNode.findParents no-longer behave as expected in 2.16.0. If I call findValues("target") for the following JSON: { "targ...
Author   gcookemoto
🌐
Baeldung
baeldung.com › home › json › jackson › using findvalue() to get the value for a nested key in jackson
Using findValue() to Get the Value for a Nested Key in Jackson | Baeldung
September 5, 2024 - String email = rootNode.findValue("email").asText(); assertEquals("[email protected]", email); Here we’ve used asText() to convert the JsonNode containing the email into a string.
🌐
Massapi
massapi.com › method › com › fasterxml › jackson › databind › JsonNode.findValue.html
Examples of com.fasterxml.jackson.databind.JsonNode.findValue() | massapi.com
com.fasterxml.jackson.databind.JsonNode.findValue() Method for finding a JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null. @param fieldName Name of field to look for ...
🌐
GitHub
github.com › FasterXML › jackson-1 › blob › master › src › java › org › codehaus › jackson › JsonNode.java
jackson-1/src/java/org/codehaus/jackson/JsonNode.java at master · FasterXML/jackson-1
public final List<JsonNode> findValues(String fieldName) { List<JsonNode> result = findValues(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; } · /** * Similar to {@link #findValues}, but will additionally convert ·
Author   FasterXML
Find elsewhere
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.jsonnode
com.fasterxml.jackson.databind.JsonNode.findValues java code examples | Tabnine
@Override public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar) { if (_children != null) { for (JsonNode node : _children) { foundSoFar = node.findValues(fieldName, foundSoFar); } } return foundSoFar; }
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › 2.9.5 › com › fasterxml › jackson › databind › class-use › JsonNode.html
Uses of Class com.fasterxml.jackson.databind.JsonNode
Bookmarks · Latest version of com.fasterxml.jackson.core:jackson-databind · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.9.5 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.9.5 · package-list path (used for javadoc generation ...
🌐
Hotexamples
java.hotexamples.com › examples › com.fasterxml.jackson.databind › JsonNode › findValue › java-jsonnode-findvalue-method-examples.html
Java JsonNode.findValue Examples, com.fasterxml.jackson.databind.JsonNode.findValue Java Examples - HotExamples
@Test public void verifyOKWithAuthorizationHeader() throws Exception { final Map<String, Object> map = new HashMap<>(); map.put(NAME, VALUE); final List<String> list = Arrays.asList(VALUE, VALUE); map.put(NAME2, list); final Principal principal = org.jasig.cas.authentication.TestUtils.getPrincipal(ID, map); final Authentication authentication = new OAuthAuthentication(ZonedDateTime.now(), principal); final AccessTokenImpl accessToken = (AccessTokenImpl) accessTokenFactory.create(TestUtils.getService(), authentication); oAuth20ProfileController.getTicketRegistry().addTicket(accessToken); final
🌐
Tabnine
tabnine.com › home page › code › java › org.codehaus.jackson.jsonnode
org.codehaus.jackson.JsonNode.findValue java code examples | Tabnine
@Override public JsonNode findValue(String fieldName) { if (_children != null) { for (Map.Entry<String, JsonNode> entry : _children.entrySet()) { if (fieldName.equals(entry.getKey())) { return entry.getValue(); } JsonNode value = entry.getValue().findValue(fieldName); if (value != null) { return value; } } } return null; } ... /** * Inspects the supplied {@link JsonNode} instance and returns the json 'failure-description' node value as text.
🌐
GitHub
github.com › codehaus › jackson › blob › master › src › java › org › codehaus › jackson › JsonNode.java
jackson/src/java/org/codehaus/jackson/JsonNode.java at master · codehaus/jackson
public final List<JsonNode> findValues(String fieldName) { List<JsonNode> result = findValues(fieldName, null); if (result == null) { return Collections.emptyList(); } return result; } · /** * Similar to {@link #findValues}, but will additionally convert ·
Author   codehaus
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.4 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.4.0 API)
Method similar to findValue(java.lang.String), but that will return a "missing node" instead of null if no field is found. Missing node is a specific kind of node for which isMissingNode() returns true; and all value access methods return empty or missing value. ... Value of first matching node found; or if not found, a "missing node" (non-null instance that has no value) public abstract JsonNode findParent(String fieldName)
Top answer
1 of 2
2

You can use elements() method and check if value key exist then add the value to list.

Smaple code

ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(data);

List<String> values = new ArrayList<>();
jsonNode.forEach(jsonObject -> jsonObject.elements().forEachRemaining(valueNode -> {
    if(valueNode.has("value"))
        values.add(valueNode.get("value").asText());
}));
System.out.println(values);

Output:

[http://www.wikidata.org/entity/Q42442324, http://www.wikidata.org/prop/direct/P21, Kiisu Miisu, http://www.wikidata.org/entity/Q43260736, http://www.wikidata.org/prop/direct/P21, Paddles]
2 of 2
0

Here is the solution by "Josson & Jossons". I list 2 more examples with condition filtering.

https://github.com/octomix/josson

implementation 'com.octomix.josson:josson:1.3.22'

---------------------------------------------

Josson josson = Josson.fromJsonString(
    "[" +
    "  {" +
    "    \"item\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/entity/Q42442324\"" +
    "    }," +
    "    \"prop\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/prop/direct/P21\"" +
    "    }," +
    "    \"itemLabel\": {" +
    "      \"xml:lang\": \"en\", \"type\": \"literal\", \"value\": \"Kiisu Miisu\"" +
    "    }" +
    "  }," +
    "  {" +
    "    \"item\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/entity/Q43260736\"" +
    "    }," +
    "    \"prop\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/prop/direct/P21\"" +
    "    }," +
    "    \"itemLabel\": {" +
    "      \"xml:lang\": \"en\", \"type\": \"literal\", \"value\": \"Paddles\"" +
    "    }" +
    "  }" +
    "]");

JsonNode node = josson.getNode("*.value");
System.out.println("1.\n" + node.toPrettyString());

node = josson.getNode("~'^item.*'.value");
System.out.println("2.\n" + node.toPrettyString());

node = josson.getNode("*[value.type='uri']*.value");
System.out.println("3.\n" + node.toPrettyString());

Output:

1.
[ "http://www.wikidata.org/entity/Q42442324", "http://www.wikidata.org/prop/direct/P21", "Kiisu Miisu", "http://www.wikidata.org/entity/Q43260736", "http://www.wikidata.org/prop/direct/P21", "Paddles" ]
2.
[ "http://www.wikidata.org/entity/Q42442324", "Kiisu Miisu", "http://www.wikidata.org/entity/Q43260736", "Paddles" ]
3.
[ "http://www.wikidata.org/entity/Q42442324", "http://www.wikidata.org/prop/direct/P21", "http://www.wikidata.org/entity/Q43260736", "http://www.wikidata.org/prop/direct/P21" ]
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › com › fasterxml › jackson › databind › node › ValueNode.html
ValueNode (The Adobe AEM Quickstart and Web Application.)
public final java.util.List<java.lang.String> findValuesAsText(java.lang.String fieldName, java.util.List<java.lang.String> foundSoFar) ... public final java.util.List<JsonNode> findParents(java.lang.String fieldName, java.util.List<JsonNode> foundSoFar)