how to decode json in php

Today, We want to share with you how to decode json in php.In this post we will show you php read json file, hear for php json stringify we will give you demo and example for implement.In this post, we will learn about Create JSON with json_encode and json_decode using PHP with an example.

PHP json_decode() Function

Store JSON data in a PHP variable, and then decode it into a PHP object:
Example 1:

<?php
$alldatamembers = '{"Dhara":25,"Kinara":37,"Jigar":43}';

var_dump(json_decode($alldatamembers));
?>

Example 2:
Store JSON data in a PHP variable, and then decode it into a PHP associative array:

<?php
$alldatamembers = '{"Dhara":25,"Kinara":37,"Jigar":43}';

var_dump(json_decode($alldatamembers, true));
?>

Example 3:
How to access the values from the PHP object:

<?php
$alldatamembers = '{"Dhara":25,"Kinara":37,"Jigar":43}';

$data = json_decode($alldatamembers);

echo $data->Dhara;
echo $data->Kinara;
echo $data->Jigar;
?>

Example 4:
How to access the values from the PHP associative array:

<?php
$alldatamembers = '{"Dhara":25,"Kinara":37,"Jigar":43}';

$arr = json_decode($alldatamembers, true);

echo $arr["Dhara"];
echo $arr["Kinara"];
echo $arr["Jigar"];
?>

I hope you get an idea about php read json file.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.