In this example, we will learn how to parse or read a JSON object using PHP built-in function.


Let’s create a separate file for the JSON.

Copy-paste the following line of the code and save the file as “test.json”



PHP provides two variants of json_decode to parse or read the JSON.

Parse JSON data using PHP

json_decode($json_string, true);

The complete code is as follows.

$json_string = file_get_contents("test.json");
$json_arry = json_decode($json_string, true);
foreach ($json_arry as $key => $value)
echo $key . " -> ". $value. "<br/>";

More PHP Snippets

Last modified: November 4, 2019


Write a Reply or Comment

Your email address will not be published.