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

  • Home
  • SEARCH
  • 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 7515311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:46:05+00:00 2026-05-30T00:46:05+00:00

I have a JSON string that resembles the following: { foo : bar, id

  • 0

I have a JSON string that resembles the following:

{
    "foo" : "bar",
    "id" : 1,
    "children":[
        {
            "some" : "string",
            "id" : 2,
            children : []
        },
        {
            "some" : "string",
            "id" : 2,
            children : []
        }
    ]
}

I do a JSON parse of this string, and that turns all objects into HashMaps and all arrays into HashMap[]s. My problem is I need a single recursive function to iterate through all nodes of this JSON structure in Java. How can I do this? I was thinking something like:

public HashMap findNode(boolean isArray, HashMap map, HashMap[] array){
    //array stuff
    if(isArray){
        for(int i=0; i<array.length(); i++){
            Object value = array[i];
            if(value instanceof String)
                System.out.println("value = "+value);
            else if(value instanceof HashMap)
                findNode(false, value, null);
            else if(value instanceof HashMap[])
                findNode(true, null, value);
        }
    //hashmap stuff
    }else{
        for(HashMap.Entry<String, Object> entry : map.entrySet()){
            Object value = entry.getValue();
            if(value instanceof String)
                System.out.println("value = "+value);
            else if(value instanceof HashMap)
                findNode(false, value, null);
            else if(value instanceof HashMap[])
                findNode(true, null, value);
        }
    }
}
  • 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-30T00:46:09+00:00Added an answer on May 30, 2026 at 12:46 am

    Assuming you an array can only have Maps inside (and not other arrays):

    public void findNode(HashMap map) {
        for(HashMap.Entry<String, Object> entry : map.entrySet()){
            Object value = entry.getValue();
            if(value instanceof String)
                System.out.println("value = "+value);
            else if(value instanceof HashMap)
                findNode(value);
            else if(value instanceof HashMap[])
                for(int i=0; i<array.length(); i++){
                    findNode(array[i]);
        }
    }
    

    Or you can make it even simpler if you can use 3 functions

    public void findNode(HashMap map) {
        for(HashMap.Entry<String, Object> entry : map.entrySet()){
            findNode(entry.getValue());
        }
    }
    
    public void findNode(String value) {
        System.out.println("value = "+value);
    }
    
    public void findNode(HashMap[] value) {
        for(int i=0; i<array.length(); i++){
            findNode(array[i]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSON code in a string that I am trying to parse.
Hi I have a JSON string that looks like this (Usingt Rails and a
I have a JSON string that looks something like this: {addresses:{address:[{@array:true,@id:888888,@uri:xyz,household:{@id:44444,@uri:xyz},person:{@id:,@uri:},addressType:{@id:1,@uri:xyz,name:Primary},address1:xyz,address2:null,address3:null,city:xyz,postalCode:111111}]}} What would be
Consider I have a JSON string of the following format: How do I parse
I have some json formatted data that I parse with JSON.parse. The problem I
i have this JSON string that i want to decode it with json_decode(); function
Ok..so i have a json string (myJson) that looks like this: {id: 1, file:
I have a JSON string (from PHP's json_encode() that looks like this: [{id: 1,
I have an PHP array parsed from a JSON string that looks like this:
I have a very large JSON string that I need to parse with in-browser

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.