I have to write a script to read a JSON file which will have information about a Data Pipeline - mainly three components - Status, Comments and Timestamp. Once I read the file in JSON, I need to print out the output for that respective Data Pipeline with all the three components. The output would look something like this as below:
Name: Apollo Status: Pending Comments: Monthly report Timestamp: 00:00
I have the following script to generate the JSON file:
<?php
$data = array(
"name"=>"Apollo",
"cob"=> array(
status=> "completed",
comment=> "Monthly report",
timestamp=> "00:00"
),
);
header('Content-Type: application/json');
echo json_encode($data);
?>
I have the following script to read the JSON file generated and to print the above required output:
<?php
$data = file_get_contents ('./cob_details.json');
$json = json_decode($data, true);
echo ('<pre>');
print_r ($json);
echo ('</pre>');
echo ('<br>output:</br>');
foreach ($json as $key => $value)
{
echo "Name: $value Status: $value]<br />";
}
?>
I am particularly new to JSON and PHP....Can you please let me know what am I missing over here in this script to get the required output or where am I going wrong?