How to convert string response into JSON object?
<p>I'm calling a third party api using <code>curl</code> from a php function. I'm getting a response in JSON format (datatype is string). I want convert that response to an object or array. I have tried <code>json_decode()</code>, but I'm getting <code>null</code>. If I display response in browser and copy paste that string response in PHP variable, I get the value. So I can't figure out what the problem is.</p>

<p>Here is my code:</p>

<pre><code>$fullUrl = 'http://example.com/api/assignment/1';
$data = AesCtr::encrypt($data, 'My Key', 256);
$curl = curl_init($fullUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, ['data' =&gt; $data]);
$curl_response = curl_exec($curl);
$curl_response = json_decode($curl_response);
echo '&lt;pre&gt;';
print_r($curl_response);
</code></pre>

<p>Here is response:</p>

<pre><code>{"identifier":"id", "items":[{"apiResult":"INVALID", "apiResultMessage":"Invalid controls. the field 'resource' is mandatory the field 'type of item' is mandatory the field 'element id' is mandatory the field 'resource' is mandatory", "id":"", "idProject":"", "nameProject":"", "refType":"", "refId":"", "idResource":"", "nameResource":"", "idRole":"", "nameRole":"", "comment":"", "assignedWork":"", "realWork":"", "leftWork":"", "plannedWork":"", "rate":"", "realStartDate":"", "realEndDate":"", "plannedStartDate":"", "plannedEndDate":"", "dailyCost":"", "newDailyCost":"", "assignedCost":"", "realCost":"", "leftCost":"", "plannedCost":"", "idle":"", "billedWork":""}] }
</code></pre>

<p><strong>I also have tried this</strong></p>

<pre><code>$curl_response = str_replace("'", "\'", $curl_response);
$curl_response = json_decode($curl_response);
</code></pre>