title: How to parse a JSON array in groovy
body: <p>I have the following array which I would like to access the key-value pairs in my Jenkinsfile.</p>
  <pre><code>[
      {
          &quot;AppName&quot;: &quot;app1&quot;,
          &quot;version&quot;: &quot;1.0.0.1&quot;
      },
      {
          &quot;AppName&quot;: &quot;app2&quot;,
          &quot;version&quot;: &quot;1.0.0.2&quot;
      },
      {
          &quot;AppName&quot;: &quot;app3&quot;,
          &quot;version&quot;: &quot;1.0.0.3&quot;
      }
  ]
  </code></pre>
  <p>I would like to get the app name and version and download the applications from my repository via a curl command. I already tried <a href="https://stackoverflow.com/questions/3855232/parsing-array-of-json-arrays-in-groovy">this solution</a> but doesn't work. I get the error on my jenkins console <code>hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String</code> . I don't know what else I am doing wrong. My plan is to download the apps with following URL for each app name and version from the array.</p>
  <pre><code>sh &quot;curl https://example.com/${AppName}/${version}/${AppName}-${version}.zip -O&quot;
  </code></pre>
  <p>Here is my jenkinsfile</p>
  <pre><code>node { 
      stage ('checkou') {
          checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'projectA/testProjectfile.json']]]], submoduleCfg: [], userRemoteConfigs: [[url: 'ssh://myrepository.com/apps/projectA.git']]])
      }
      stage ('read file') {
          def data = readFile(file: &quot;${WORKSPACE}/projectA/testProjectfile.json&quot;)
          echo &quot;$data&quot;
          def list = new JsonSlurper().parseText( data )
          list.each { println it }
          
      }
      
      stage ('download app') {
          sh &quot;curl https://example.com/${AppName}/${version}/${AppName}-${version}.zip -O&quot;
      
      }
  }
  </code></pre>
  <p>That is my Jenkinsfile and here is the log when I run the pipeline</p>
  <pre><code>[Pipeline] echo
  [
      {
        &quot;AppName&quot;: &quot;app1&quot;,
        &quot;version&quot;: &quot;1.0.0.1&quot;
      },
      {
        &quot;AppName&quot;: &quot;app2&quot;,
        &quot;version&quot;: &quot;1.0.0.2&quot;
      },
      {
        &quot;AppName&quot;: &quot;app3&quot;,
        &quot;version&quot;: &quot;1.0.0.3&quot;
      }
  ]
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String
      at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143)
      at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103)
      at net.sf.json.groovy.JsonSlurper.parseText(JsonSlurper.java:80)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
  </code></pre>