PHP json_decode() Function

PHP json_decode() Function is used to decode JSON array or a JSON object into a PHP object or an associative array.  A json_decode() function is built-in function in PHP.

Syntax :

json_decode(json $jsondata,$flag = false);

Parameter,

$array: Required. It is a input jsondata.

$flag : Optional. Default value is false. If It set to true, JSON objects are decoded into associative arrays. If It set to false, JSON objects are decoded into php objects.

Return Values :

It returns a PHP object or associative array for JSON Data.

JSON Data can be decoded into php object by using the PHP function json_decode().

Let's see below example to understand php json_decode() Function in details.

Example :

<?php
echo "<br>Below example shows how to decode a JSON object into php objects<br>";
$jsondata = '{"John":99,"Herry":76,"roze":47,"Jack":85}';
$phpobj = json_decode($jsondata);
echo "<br>".$phpobj->John ;
echo "<br>".$phpobj->Herry;
echo "<br>".$phpobj->roze;
echo "<br>".$phpobj->Jack;

echo "<br><br>Below example shows how to decode a JSON object into an associative array<br>";
$array=json_decode($jsondata ,true);
print_r($array);
?>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

59564