Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:08:36+00:00 2026-05-26T02:08:36+00:00

How can I receive the node names from a JSON tree using Jackson? The

  • 0

How can I receive the node names from a JSON tree using Jackson?
The JSON-File looks something like this:

{  
    node1:"value1",
    node2:"value2",
    node3:{  
        node3.1:"value3.1",
        node3.2:"value3.2"
    }
}

I have

JsonNode rootNode = mapper.readTree(fileReader);

and need something like

for (JsonNode node : rootNode){
    if (node.getName().equals("foo"){
        //bar
  }
}

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:08:37+00:00Added an answer on May 26, 2026 at 2:08 am

    This answer applies to Jackson versions prior to 2+ (originally written for 1.8). See @SupunSameera’s answer for a version that works with newer versions of Jackson.


    The JSON terms for “node name” is “key.” Since JsonNode#iterator()
    does not include keys, you need to iterate differently:

    for (Map.Entry<String, JsonNode> elt : rootNode.fields())
    {
        if ("foo".equals(elt.getKey()))
        {
            // bar
        }
    }
    

    If you only need to see the keys, you can simplify things a bit with JsonNode#fieldNames():

    for (String key : rootNode.fieldNames())
    {
        if ("foo".equals(key))
        {
            // bar
        }
    }
    

    And if you just want to find the node with key "foo", you can access it directly. This will yield better performance (constant-time lookup) and cleaner/clearer code than using a loop:

    JsonNode foo = rootNode.get("foo");
    if (foo != null)
    {
        // frob that widget
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to get this right. class Tree { Node* root; vector& dict;
how can i receive a file sent by an applet to the server by
I receive TypeError: Can't convert 'float' object to str implicitly while using Gambler.pot +=
How can i send and receive data though parallel port using C# .net? Also
How can I open a web-page and receive its cookies using PHP? The motivation
How can I change the attributes of a tree node? One tree node has
I've a tree-like polymorphic data-structure, where the nodes are instances of class Node (implemented
Can you recommend a library for .NET that can receive FAXes? Window Fax server
I implemented IDispatchMessageInspector and in method AfterReceiveRequest I can receive name of method (action)
How can I receive and send email in python? A 'mail server' of sorts.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.