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:

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


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

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

var_dump(json_decode($alldatamembers, true));

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

$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:

$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 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.

Read Also:  insert delete image from folder in php with jQuery

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Add JSON object Data Example
  2. Read Also:  CodeIgniter Insert Records into MySQL database Example
  3. Read Also:  php read csv file into array Examples
  4. Read Also:  PHP Laravel delete files from Public Folder
  5. Read Also:  How to convert php array to json object with example?
  6. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  7. Read Also:  PHP JQuery Ajax Request POST Data
  8. Read Also:  Converting JSON Object into Javascript PHP array
  9. Read Also:  Get last inserted record ID mySQL using PHP
  10. Read Also:  jQuery Parsing PHP JSON Data