Welcome to TheOpenHost | 24x7 Technical Support

PHP json decode

The json_decode function takes a JSON encoded string and converts it into a PHP variable. You may get a JSON string via an API call to a third party, for example.

Here is a sample of PHP code with the JSON string hard coded, just for clarity:

$json_data = '{"Dogs":1,"Cats":7,"Elephants":3,"Cobras":4,"Bees":5533}';
$json_object = json_decode($json_data);

and it outputs:

 stdClass Object ( [Dogs] => 1 [Cats] => 7 [Elephants] => 3 [Cobras] => 4 [Bees] => 5533 ) 

That’s it — it’s easy. 🙂

Copyright © 2019 TheOpenHost