title: How can I parse a JSON object in PHP? How can I retrieve the values of some specific fields of this JSON object?
body: <p>I am absolutely new in PHP and moreover in Laravel framework (I don't know if Laravel provides some utility class for this kind of tasks). I came from Java.</p>
  
  <p>So I have the following problem:</p>
  
  <p>Into a class I perform a call to a REST web service, something like this:</p>
  
  <pre><code>    $response = $client-&gt;get('http://localhost:8080/Extranet/login',
          [
              'auth' =&gt; [
                  'dummy@gmail.com',
                  'pswd'
              ]
          ]);
  
      $dettagliLogin = json_decode($response-&gt;getBody());
  
     \Log::info('response: '.(json_encode($dettagliLogin)));
  </code></pre>
  
  <p><code>$response-&gt;getBody()</code> contains the returned JSON object, this is the output of the previous <code>\Log::info()</code>:</p>
  
  <pre><code>{
      "id":5,
      "userName":"Dummy User",
      "email":"dummy@gmail.com",
      "enabled":true
  } 
  </code></pre>
  
  <p>So I have the following problems:</p>
  
  <p>1) What exactly returns the <code>json_decode()</code> function? I really can't understand because PHP is not strongly typed and I have not a declared return type.</p>
  
  <p>This is the method signature:</p>
  
  <pre><code>function json_decode($json, $assoc = false, $depth = 512, $options = 0)
  </code></pre>
  
  <p>and in the related doc it says <code>@return mixed</code>. What exactly means "mixed"? </p>
  
  <p>2) Anyway the main problem is: I have to use the content of the previous returned JSON object and put these value into the related field of an array like this:</p>
  
  <pre><code>$attributes = array(
      'id' =&gt; HERE THE id FIELD VALUE OF MY JSON OBJECT,
      'username' =&gt; HERE THE email FIELD VALUE OF MY JSON OBJECT',
      'name' =&gt; HERE THE userName FIELD VALUE OF MY JSON OBJECT,
      );
  </code></pre>
  
  <p>So I think that I have to parse the value of the <code>$response-&gt;getBody()</code> or of the <code>json_decode($response-&gt;getBody())</code> to obtain these values. But how exactly can I do it? What is the neater way to do it? Does the Laravel framework provide some utility to do it?</p>