- json_decode: documentation ( source)
<?php
$str = '{
"ip": "8.8.8.8",
"hostname": "google-public-dns-a.google.com",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.3860,-122.0838",
"org": "AS15169 Google Inc.",
"postal": "94040"
}';
$json = json_decode($str, true);
echo $country = $json['country'];