title: Extracting JSON from cURL results
body: <p>I'm new to regex and I'm trying to grab the JSON response from a cURL request in PHP.</p>
  
  <p>I was thinking of using preg_match_all. </p>
  
  <p><em>Edit</em>: Should have mentioned the full response from curl_exec() includes header information which is why I need to extract the JSON.</p>
  
  <pre><code>HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 WWW-Authenticate:  Digest realm="",  qop="auth", [... etc]
  </code></pre>
  
  <p>The JSON I want looks something like this (following all headers):</p>
  
  <pre><code>{  "requests" :  
    [ { 
       "request_id" : 10298, 
       "name" : "CURL Test2",  
       "submitter" : "First Last",  
       "hide" : false,  
       "priority" : 10,  
       "tags" : [ "label 2" ],  
       "body" : 
            { "type" : "html", "content" : "" },  
       "runs" : 0  
     } ] 
    }
  </code></pre>
  
  <p>Was hoping to just grab everything between the curly braces. However, when I do this it grabs everything from the <strong>first opening brace</strong> to the <strong><em>first</em></strong> closing brace. For extensibility, I just want to grab everything within and including the first opening brace and the <strong><em>last</em></strong> closing brace.</p>
  
  <p>Technically it could just start at the first opening brace and return everything until end of the response (there's nothing following the JSON).</p>
  
  <p>Thoughts?</p>