Simple json_decode() Example

stdClass Object ( [user] => John [age] => 22 [country] => United States )

user | John

age | 22

country | United States


<?php
$jsonData = '{ "user":"John", "age":22, "country":"United States" }';
$phpArray = json_decode($jsonData);
print_r($phpArray);
foreach ($phpArray as $key => $value) { 
    echo "<p>$key | $value</p>";
}
?>

Deeply Nested Example

u1

user | John
age | 22
country | United States

u2

user | Will
age | 27
country | United Kingdom

u3

user | Abiel
age | 19
country | Mexico

<?php
$jsonData = '{ 
"u1":{ "user":"John", "age":22, "country":"United States" },
"u2":{ "user":"Will", "age":27, "country":"United Kingdom" },
"u3":{ "user":"Abiel", "age":19, "country":"Mexico" }
}';
$phpArray = json_decode($jsonData, true);
foreach ($phpArray as $key => $value) { 
    echo "<h2>$key</h2>";
    foreach ($value as $k => $v) { 
        echo "$k | $v <br />"; 
    }
}
?>

Call in JSON File and Parse Using PHP

u1

user | John
age | 22
country | United States

u2

user | Will
age | 27
country | United Kingdom

u3

user | Abiel
age | 19
country | Mexico

u4

user | Rick
age | 34
country | Panama

u5

user | Susan
age | 23
country | Germany

u6

user | Amy
age | 43
country | France

json_decode()