title: How to use curl in C and parse JSON response
body: <p>The code below compiles and prints the response.</p>
  <p>My question is: being the response a string which represents an object, how can I cast &quot;res&quot; into a string or directly into a JSON object?</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;curl/curl.h&gt;
  #include &lt;json-c/json.h&gt;
  
  int main(int argc, char **argv) {
      CURL *curl;
      CURLcode res;
      curl = curl_easy_init();
  
      if(curl) {
          curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, &quot;GET&quot;);
          curl_easy_setopt(curl, CURLOPT_URL, &quot;http://localhost:8080/system/genpass&quot;);
          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
          curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, &quot;https&quot;);
          struct curl_slist *headers = NULL;
          headers = curl_slist_append(headers, &quot;length: 20&quot;);
          headers = curl_slist_append(headers, &quot;numbers: true&quot;);
          curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
          res = curl_easy_perform(curl);
          printf(&quot;%u&quot;,res);
      }
  
      curl_easy_cleanup(curl);
  }
  </code></pre>