Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <strong><a href="http://www.php.net/json_decode" rel="noreferrer"><code>json_decode</code></a></strong> function to decode the JSON string :</p> <pre><code>$json = &lt;&lt;&lt;JSON { "programmers": [ { "firstName": "Brett", "lastName":"McLaughlin" }, { "firstName": "Jason", "lastName":"Hunter" }, { "firstName": "Elliotte", "lastName":"Harold" } ], "authors": [ { "firstName": "Isaac", "lastName": "Asimov" }, { "firstName": "Tad", "lastName": "Williams" }, { "firstName": "Frank", "lastName": "Peretti" } ], "musicians": [ { "firstName": "Eric", "lastName": "Clapton" }, { "firstName": "Sergei", "lastName": "Rachmaninoff" } ] } JSON; $data = json_decode($json); </code></pre> <p><br> Then, to see what the data looks like, you can dump it :</p> <pre><code>var_dump($data); </code></pre> <p><br> And you'll see you have an object containing three arrays, each one containing other sub-objects :</p> <pre><code>object(stdClass)[1] public 'programmers' =&gt; array 0 =&gt; object(stdClass)[2] public 'firstName' =&gt; string 'Brett' (length=5) public 'lastName' =&gt; string 'McLaughlin' (length=10) 1 =&gt; object(stdClass)[3] public 'firstName' =&gt; string 'Jason' (length=5) public 'lastName' =&gt; string 'Hunter' (length=6) ... public 'authors' =&gt; array 0 =&gt; object(stdClass)[5] public 'firstName' =&gt; string 'Isaac' (length=5) public 'lastName' =&gt; string 'Asimov' (length=6) ... </code></pre> <p>Which means you know how to access your data.</p> <p><br> For example, to display the list of the programmers, you could use :</p> <pre><code>foreach ($data-&gt;programmers as $programmer) { echo $programmer-&gt;firstName . ' ' . $programmer-&gt;lastName . '&lt;br /&gt;'; } </code></pre> <p><br> Which would get you the following output :</p> <pre><code>Brett McLaughlin Jason Hunter Elliotte Harold </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload