$jsonString = '{"name":"John", "age":30, "city":"New York"}'; $obj = json_decode($jsonString); echo $obj->name; // outputs "John" echo $obj->age; // outputs 30 echo $obj->city; // outputs "New York"
$jsonString = '{"name":"John", "age":30, "city":"New York"}'; $arr = json_decode($jsonString, true); echo $arr["name"]; // outputs "John" echo $arr["age"]; // outputs 30 echo $arr["city"]; // outputs "New York"The json_decode() function is part of the PHP standard library, so no additional package or library is required. However, it is important to ensure that the JSON string is valid before decoding it. The function will return NULL if the JSON string is not valid, which could cause unexpected behavior in your code.