1$personJSON = '{"name":"Johny Carson","title":"CTO"}';
2
3$person = json_decode($personJSON);
4
5echo $person->name; // Johny Carson
1<?php
2
3$json = '{"firstName":"Peter","lastName:":"Silva","age":23}';
4
5$personInfo = json_decode(json);
6
7echo $personInfo->age;
8
9?>
1// Checks if json
2function isJson($string) {
3 json_decode($string);
4 return json_last_error() === JSON_ERROR_NONE;
5}
6
7// example
8if (isJson($string) {
9 // Do your stuff here
10}