title: Groovy: Parsing JSON file
body: <p>I am quite new to Groovy and I am parsing a JSON file with following code:</p>
  
  <pre><code>void getItemData()
  {
      def jsonSlurper = new JsonSlurper()
      def reader = new BufferedReader(new InputStreamReader(new FileInputStream("data.json"),"UTF-8"));
      data = jsonSlurper.parse(reader);       
      data.TESTS.each{println  it.MEMBER_ID}
  }
  </code></pre>
  
  <p>And I am getting printed properly the value of MEMBER_ID.</p>
  
  <p>I want to Parameterize the above function like:</p>
  
  <pre><code>void getItemData(String item)
  {
      ...
  }
  </code></pre>
  
  <p>so that I can call this function with the desired item I want. For example: I want the MEMBER_ADDRESS. I want to call the function like: </p>
  
  <pre><code>getItemData("MEMBER_ADDRESS")
  </code></pre>
  
  <p>Now How I should change the statement:</p>
  
  <pre><code>data.TESTS.each{println  it.MEMBER_ID}
  </code></pre>
  
  <p>I tried with</p>
  
  <pre><code>it.${item}
  </code></pre>
  
  <p>and some other ways not working.</p>
  
  <p>Please teach me how to do it.</p>
  
  <p>My JSON file is like below:</p>
  
  <pre><code>{
      "TESTS": 
      [
           {
                "MEMBER_ID": "my name",
                "MEMBER_ADDRESS": "foobarbaz",
           }
      ]
  }
  </code></pre>