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
Contents
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.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.