I am new to regex and am trying to get a JSON response from a cURL request in PHP.
I thought to use preg_match_all.
Edit: Should have mentioned the full answer from curl_exec (), including the header information, so I need to extract the JSON.
HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 WWW-Authenticate: Digest realm="", qop="auth", [... etc]
JSON I want to look something like this (after all the headers):
{ "requests" : [ { "request_id" : 10298, "name" : "CURL Test2", "submitter" : "First Last", "hide" : false, "priority" : 10, "tags" : [ "label 2" ], "body" : { "type" : "html", "content" : "" }, "runs" : 0 } ] }
I just wanted to take everything between curly braces. However, when I do this, it captures everything from the first open parenthesis to the first trailing curly bracket. For extensibility, I just want to capture everything inside and including the first open curly brace and the closing last bracket.
Technically, this can only begin with the first open bracket and return everything to the end of the response (nothing follows JSON there).
Thoughts?
source share