title: Iterate recursively through deep HashMap
body: <p>I have a JSON string that resembles the following:</p>
  
  <pre><code>{
      "foo" : "bar",
      "id" : 1,
      "children":[
          {
              "some" : "string",
              "id" : 2,
              children : []
          },
          {
              "some" : "string",
              "id" : 2,
              children : []
          }
      ]
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>public HashMap findNode(boolean isArray, HashMap map, HashMap[] array){
      //array stuff
      if(isArray){
          for(int i=0; i&lt;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&lt;String, Object&gt; 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);
          }
      }
  }
  </code></pre>