Echo JSON response with PHP
<p>I am trying to echo a portion of my JSON response from the Plaid API.  </p>

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

<pre><code>$data = array(
            "client_id"=&gt;"test_id",
            "secret"=&gt;"test_secret",
            "public_token"=&gt;"test,fidelity,connected");
        $string = http_build_query($data);

    //initialize session
    $ch=curl_init("https://tartan.plaid.com/exchange_token");

    //set options
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    //execute session
    $exchangeToken = curl_exec($ch);
    echo $exchangeToken;
    $exchangeT = json_decode($exchangeToken);
    echo $exchangeT['access_token'];
    //close session
    curl_close($ch);
</code></pre>

<p>Here is the response:</p>

<pre><code>{ "sandbox": true, "access_token": "test_fidelity" }
</code></pre>

<p>I also get a 500 Internal Server Error, which results from the echo $exchangeT line.  I want to take the access_token portion of the JSON response, echo it to verify, and eventually save it to a database.</p>