title: Pull out nested Maps/EntrySets from JSON with Groovy when criteria met
body: <p>Big trouble out in code-land and thus I am in need of help!</p>
  
  <p>Using Groovy and JsonSlurper I am processing JSON of the form below.  I am looking for the outside containing element (in my case this all SHOULD be Maps) when a "type" key is set to a certain value.  For instance, if the type was "Type5", then I need to get three Maps back: the 'body' Map that contains the outer Type5, the 'body' Map that contains the INNER Type5, and the Type5 Map near the bottom (an EntrySet for each would work fine as well).  Type3 and Type4 exhibit the same behavior!</p>
  
  <p><strong>Edited per request to have valid Json</strong></p>
  
  <p>I ran this through Groovy's JsonSlurper so it should be valid.</p>
  
  <pre><code>{
  "type": "Run1",
  "body": [
  {
    "type": "Type1",
    "expression": {
      "type": "Type2",
      "expressions": [
        {
          "type": "Type3",
          "body": {
            "type": "Type4",
            "id": null,
            "params": [
              {
                "type": "Identifier",
                "name": "a"
              },
              {
                "type": "Identifier",
                "name": "b"
              },
              {
                "type": "Identifier",
                "name": "c"
              }
            ],
            "body": {
              "type": "Type5",
              "body": [
                {
                  "type": "Type6",
                  "id": {
                    "type": "Identifier",
                    "name": "d"
                  },
                  "params": [
                    {
                      "type": "Identifier",
                      "name": "a"
                    }
                  ],
                  "body": {
                    "type": "Type5",
                    "body": [
                      {
                        "type": "Type7",
                        "contents": {
                          "type": "Type8",
                          "leftcontents": {
                            "type": "Literal",
                            "value": "specific name",
                          },
                          "rightcontents": {
                            "type": "Type3",
                            "body": {
                              "type": "Type4",
                              "object": {
                                "type": "Identifier",
                                "name": "o"
                              },
                              "property": {
                                "type": "Identifier",
                                "name": "f"
                              }
                            },
                            "contents": [
                              {
                                "type": "Identifier",
                                "name": "a"
                              }
                            ]
                          }
                        }
                      }
                    ]
                  },
                },
                {
                  "type": "Type6",
                  "id": {
                    "type": "Identifier",
                    "name": "e"
                  },
                  "params": [
                    {
                      "type": "Identifier",
                      "name": "a"
                    }
                  ],
                  "defaults": [],
                  "body": {
                    "type": "Type5",
                    "body": [
                      {
                        "type": "Type7",
                        "contents": {
                          "type": "Type8",
                          "leftcontents": {
                            "type": "Literal",
                            "value": "string",
                          },
                          "rightcontents": {
                            "type": "Type9",
                            "argument": {
                              "type": "Identifier",
                              "name": "a"
                            },
                            "prefix": true
                          }
                        }
                      }
                    ]
                  },
                }
              ]
            }
          }
        }
      ]
    }
  }
  ]
  }
  </code></pre>
  
  <p>I am just doing this:</p>
  
  <pre><code>FileInputStream fis = new FileInputStream('myInput.json')
  def jsonData = (new JsonSlurper()).parse(fis)
  </code></pre>
  
  <p>although I can readily access individual parts of the structure, to get all the "Type5"s that have arbitrary nesting levels is beyond me.  Can anyone shine some brilliance on this?</p>