To do a proper null check of a JsonNode field:

JsonNode jsonNode = response.get("item");

if(jsonNode == null || jsonNode.isNull()) { }

The item is either not present in response, or explicitly set to null .

Answer from Snoi Singla on Stack Overflow
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.6 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.6.0 API) - FasterXML
Method that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (including properties with explicit null values), returns true; otherwise returns false.
Discussions

Missing JsonNode field deserialized to null instead of NullNode
Describe the bug There's a behavior change between 2.12.6 and 2.13.0. Until then a missing JsonNode field was deserialized as a NullNode and it now is deserialized to Java null. Version informa... More on github.com
🌐 github.com
3
January 31, 2022
Why isEmpty( ) always returns true for jsonNode.get("some_key").isEmpty( )? Method isEmpty( ) works properly only if I add .asText( ) method: jsonNode.get("some_key").asText( ).isEmpty( );
https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonNode.html#get(java.lang.String) public JsonNode get(String fieldName) Method for accessing value of the specified field of an object node. If this node is not an object (or it does not have a value for specified field name), or if there is no field with such name, null is returned. NOTE: if the property value has been explicitly set as null (which is different from removal!), a NullNode will be returned, not null. https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonNode.html#asText() public abstract String asText() Method that will return a valid String representation of the container value, if the node is a value node (method isValueNode() returns true), otherwise empty String. When you call isEmpty() on the result of asText() you are calling the String.isEmpty() https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#isEmpty() From what I can tell the JsonSerializable.Base class doesn't have an isEmpty() method only an isEmpty(SerializerProvider serializers) https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonSerializable.Base.html More on reddit.com
🌐 r/javahelp
5
0
August 2, 2021
Add `JsonNode.isEmpty()` as convenience alias
There was an error while loading. Please reload this page · An often-used idiom for checking for empty Arrays and Object for JsonNode is: More on github.com
🌐 github.com
0
December 11, 2018
Check if JSON key is null in IF node
Hello, Apologies for the likely beginner-level question. I’m using a function to create a simple JSON object: { "notNull":"notNull", "Null":null } I would like to create an IF node to check whether the “Null” key is actually null. I’ve seen other similar questions but they seem to be ... More on community.n8n.io
🌐 community.n8n.io
1
0
October 22, 2020
🌐
Fasterxml
fasterxml.github.io › jackson-core › javadoc › 1.9 › org › codehaus › jackson › node › NullNode.html
NullNode (Jackson JSON Processor) - FasterXML
Overrides: isNull in class JsonNode · public String asText() Description copied from class: JsonNode · Method that will return valid String representation of the container value, if the node is a value node (method JsonNode.isValueNode() returns true), otherwise empty String.
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.jsonnode
com.fasterxml.jackson.databind.JsonNode.isNull java code examples | Tabnine
public static String getValueAsString(String name, JsonNode objectNode) { String propertyValue = null; JsonNode propertyNode = objectNode.get(name); if (propertyNode != null && !propertyNode.isNull()) { propertyValue = propertyNode.asText(); } return propertyValue; }
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 3389
Missing JsonNode field deserialized to null instead of NullNode · Issue #3389 · FasterXML/jackson-databind
January 31, 2022 - public static class MyObject { public JsonNode jsonNode; @JsonCreator public MyObject(@JsonProperty("jsonNode") JsonNode jsonNode) { this.jsonNode = jsonNode; } } @Test void nullNodeTest() throws JsonMappingException, JsonProcessingException { String json = "{}"; ObjectMapper mapper = new ObjectMapper(); MyObject object = mapper.readValue(json, MyObject.class); assertNotNull(object.jsonNode); assertInstanceOf(NullNode.class, object.jsonNode); }
Author   the8tre
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.4 › com › fasterxml › jackson › databind › node › NullNode.html
NullNode (jackson-databind 2.4.0 API)
Method similar to JsonNode.asText(), except that it will return defaultValue in cases where null value would be returned; either for missing nodes (trying to access missing property, or element at invalid item for array) or explicit nulls. Overrides: asText in class JsonNode ·
🌐
Codersee
blog.codersee.com › home › what is the difference between jackson nullnode and null?
What Is The Difference Between Jackson NullNode and Null? - Codersee
April 16, 2025 - null value, in terms of dealing with JsonNode, simply means that name/value pair does not exist for a given name
Top answer
1 of 2
2
https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonNode.html#get(java.lang.String) public JsonNode get(String fieldName) Method for accessing value of the specified field of an object node. If this node is not an object (or it does not have a value for specified field name), or if there is no field with such name, null is returned. NOTE: if the property value has been explicitly set as null (which is different from removal!), a NullNode will be returned, not null. https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonNode.html#asText() public abstract String asText() Method that will return a valid String representation of the container value, if the node is a value node (method isValueNode() returns true), otherwise empty String. When you call isEmpty() on the result of asText() you are calling the String.isEmpty() https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#isEmpty() From what I can tell the JsonSerializable.Base class doesn't have an isEmpty() method only an isEmpty(SerializerProvider serializers) https://fasterxml.github.io/jackson-databind/javadoc/2.8/com/fasterxml/jackson/databind/JsonSerializable.Base.html
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Find elsewhere
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 2204
Add `JsonNode.isEmpty()` as convenience alias · Issue #2204 · FasterXML/jackson-databind
December 11, 2018 - An often-used idiom for checking for empty Arrays and Object for JsonNode is: if (arrayNode.size() == 0) { // is empty } and due to common use, would make sense to allow use via alias if (arrayNode.isEmpty()) { ... } Semantically it make...
Author   cowtowncoder
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-jsonnode.html
Jackson JsonNode
The at() method returns a JsonNode ... to call one of the methods covered in the next section. If no node matches the given path expression, null will be returned....
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › cloud-service › javadoc › com › fasterxml › jackson › databind › node › NullNode.html
NullNode (The Adobe Experience Manager SDK 2022.11.9850.20221116T162329Z-220900)
Method that may be called to verify that this node is neither so-called "missing node" (that is, one for which JsonNode.isMissingNode() returns true) nor "null node" (one for which JsonNode.isNull() returns true). If non-null non-missing node, this is returned to allow chaining; otherwise ...
🌐
Red Hat
access.redhat.com › webassets › avalon › d › red_hat_jboss_enterprise_application_platform › 8.0 › javadocs › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (Red Hat JBoss Enterprise Application Platform 8.0.0.GA public API)
Method is functionally equivalent to path(index).required() and can be used to check that this node is an ArrayNode (that is, represents JSON Array value) and has value for specified index (but note that value may be explicit JSON null value).
🌐
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 that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (including properties with explicit null values), returns true; otherwise returns false.
🌐
GitHub
github.com › IBM › JSONata4Java › issues › 165
Passing a JsonNode which contains ...
July 8, 2021 - body.isMissingNode == true). I wonder if the root cause is in Binding constructor where there is an empty case MISSING? It seems to be OK if the JsonNode is null and body.isNull() == false;
Author   JDUNNIN
Top answer
1 of 1
1

The issues lies in the meaning of null in this context. In the problematic case, clearly op has been instantiated and is therefore not null. This can be shown by adding another output line in the constructor performing the validation:

System.out.println("    class:" + (null == op ? "Real Null" : op.getClass().toString()));

This, when the program is run again, produces the folloiwng output:

Initial value: {"type":"CREATE","op":null}
Document value: {"@type":"CrudOperation","type":"CREATE"}
 isUpdate: false
isNotNull: false
  isValid: false
    class:class com.fasterxml.jackson.databind.node.NullNode
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.cyberfront.test.json.nll.demonstration.CrudOperation, problem: Operation Failed Validation: {"type":"CREATE","op":null}
 at [Source: N/A; line: -1, column: -1]
Reconstructed: null

That is, op is instantiated as a NullNode object type, which when the toString() method is performed upon it, returns null as a string not as the type.

A solution to resolving this is use of the JsonNode.isNull() method to detect when this case arises.

@JsonCreator
public CrudOperation(@JsonProperty("type") Type type, @JsonProperty("op") JsonNode op) {
    this.type = type;
    this.op = null == op || op.isNull() ? null : op;

    boolean isUpdate = Type.UPDATE.equals(this.getType());
    boolean isNotNull = null == this.getOp();
    boolean isValid = isUpdate ^ isNotNull;

    if (!isValid) {
        System.out.println(" isUpdate: " + String.valueOf(isUpdate));
        System.out.println("isNotNull: " + String.valueOf(isNotNull));
        System.out.println("  isValid: " + String.valueOf(isValid));
        System.out.println("    class:" + (null == op ? "Real Null" : op.getClass().toString()));

        throw new IllegalArgumentException("Operation Failed Validation: " + this.toString());
    }
}

This additional check for isNull() will filter out the case where a JsonNode is an instantiated null node, and will provide

Initial value: {"type":"CREATE","op":null}
Document value: {"@type":"CrudOperation","type":"CREATE"}
Reconstructed: {"type":"CREATE","op":null}

This achieves the desired result.

🌐
Stack Overflow
stackoverflow.com › questions › 75156336 › how-to-check-jsonnode-value-is-empty-or-not-java › 75156547
spring - How to check JsonNode value is empty or not : java - Stack Overflow
In java, JsonNode myObj = {name: ""}; is not a legal statement. – alalalala Commented Jan 18, 2023 at 9:13 · Add a comment | Sorted by: Reset to default · Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 0 · Have you tried something like this: node != null && !node.isNull() && node.textValue().isEmpty() Share ·
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 3214
For an absent property Jackson injects `NullNode` instead of `null` to a JsonNode-typed constructor argument of a `@ConstructorProperties`-annotated constructor · Issue #3214 · FasterXML/jackson-databind
July 15, 2021 - package jacksontests; import java.beans.ConstructorProperties; import org.junit.Assert; import org.junit.Test; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class JsonNodeNullTest { public static class TestClass { private final JsonNode nodeFromConstructor; private JsonNode nodeFromSetter; @ConstructorProperties("nodeFromConstructor") public TestClass(JsonNode nodeFromConstructor) { this.nodeFromConstructor = nodeFromConstructor; } public JsonNode getNodeFromSetter() { return nodeFromSetter; } public void setNodeFromSetter(JsonNode n
Author   robvarga
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Method that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (including properties with explicit null values), returns true; otherwise returns false.