title: Parsing InputStream into Json object and getting a value
body: <h1>The response json:</h1>
  
  <pre><code>{
      "filename": "vcops-6.0.0-MPforAWS-1.1-1695068.pak",
      "links": [
          {
              "rel": "pak_information",
              "href": "https://&lt;IP&gt;:443/casa/upgrade/cluster/pak/MPforAWS-600/information"
          },
          {
              "rel": "pak_file_information",
              "href": "https://&lt;IP&gt;:443/casa/upgrade/slice/pak/MPforAWS-600/file_information"
          },
          {
              "rel": "pak_cluster_status",
              "href": "https://&lt;IP&gt;:443/casa/upgrade/cluster/pak/MPforAWS-600/status"
          }
      ],
      "pak_id": "MPforAWS-600"
  }
  </code></pre>
  
  <p>I am using one helper of the framework we have. Framework returns response as "InputStream".
  I want to get "pak_id" from this "InputStream". I tried with <code>inputStreamObj.toString()</code> this does not work for me.</p>
  
  <p>The method I am using is:</p>
  
  <pre><code>private String getPakId(InputStream uploadResponse) {
      String pakId = null;
      try {
          String responseString = readInputStream(uploadResponse);
          JSONObject jObj = new JSONObject(responseString);
          pakId = jObj.getString("pak_id").trim();
          Reporter.log("Pak id is=" + pakId, true);
      } catch (Exception e) {
          Reporter.log("Error in getting pak_id " + e.getMessage(), true);
      }
      return pakId;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>private String readInputStream(InputStream inputStream) throws IOException {
      BufferedReader reader = new BufferedReader(new InputStreamReader(
              inputStream, "UTF-8"));
      String tmp;
      StringBuilder sb = new StringBuilder();
      while ((tmp = reader.readLine()) != null) {
          sb.append(tmp).append("\n");
      }
      if (sb.length() &gt; 0 &amp;&amp; sb.charAt(sb.length() - 1) == '\n') {
          sb.setLength(sb.length() - 1);
      }
      reader.close();
      return sb.toString();
  }
  </code></pre>