how to get data from json array in php? (php json parsing)

Today, We want to share with you php json parsing.In this post we will show you php json_decode example, hear for how to get data from json array in php? 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.

How to Encode and Decode JSON Data in PHP?

{
    "book": {
        "name": "Krunal Sisodiya and Ankit kathiriya",
        "author": "I. D. Parmar",
        "year": 2021,
        "genre": "Welcome Pakainfo",
        "bestseller": true
    }
}
{
    "languages": [
        "Tamil",
        "Hindi",
        "English",
        "Gujrati"
    ]
}

Encoding JSON Data in PHP

65, "Ravee"=>80, "Kene"=>78, "Radha"=>90);
 
echo json_encode($marks);
?>
{"Dhara":65,"Ravee":80,"Kene":78,"Radha":90}

encode the PHP indexed array into a JSON array


["Tamil","Hindi","English","Gujrati","Malayam"]

using the JSON_FORCE_OBJECT option,


{"0":"Tamil","1":"Hindi","2":"English","3":"Gujrati"}

Decoding JSON Data in PHP


object(stdClass)#1 (4) { ["Dhara"]=> int(65) ["Ravee"]=> int(80) ["Kene"]=> int(78) ["Radha"]=> int(90) }

By default the json_decode() function


array(4) { ["Dhara"]=> int(65) ["Ravee"]=> int(80) ["Kene"]=> int(78) ["Radha"]=> int(90) }

JSON object or array in PHP

Dhara;   // Result: 65
echo $obj->Ravee;   // Result: 80
echo $obj->Kene;    // Result: 78
echo $obj->Radha;   // Result: 90
?>

decoded data using foreach() loop

$value){
    echo $key . "=>" . $value . "
"; } echo "
"; $obj = json_decode($json); foreach($obj as $key=>$value){ echo $key . "=>" . $value . "
"; } ?>

Extracting Values from Nested JSON Data in PHP


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.

Leave a Comment