title: Groovy script: How to parse/format Json in groovy in each loop
body: <p>I am new on Groovy, I am trying to mock a service in soap ui.</p>
  
  <p>Requirement is to load a text file with json data, and load a node with matching data.</p>
  
  <p>whati have tried is as below,</p>
  
  <pre><code>def inputFile = new File("D:\\Users\\json.txt")
  def InputJSON = new JsonSlurper().parseText(inputFile.text)
  
      InputJSON.each{  
          def ID1 = it
          it.items.each { 
              if(it.Number == itemNumber) 
              {
                  log.info it
                  requestContext.Id = ID1
              } 
          }
      }
  </code></pre>
  
  <p>This works perfectly fine just one issue, is the format.
  when ID1 loads into requestContext.Id, the format of json is lost from the file.</p>
  
  <p>What I need is </p>
  
  <pre><code>{
   "items" {
          "number" : 1475175072691
        }
  }
  </code></pre>
  
  <p>what i get is</p>
  
  <pre><code>{
   metadata = {
          timestamp = 1475175072691
  }
  }
  </code></pre>
  
  <p>Why does it take away the double quotes <strong>"</strong> and colon <strong>:</strong> from my json.
  Please suggest.</p>