What are some common pitfalls when accessing nested data in JSON files using PHP?

One common pitfall when accessing nested data in JSON files using PHP is not properly handling nested arrays or objects within the JSON structure. To access nested data, you need to traverse through each level of the nested structure using the appropriate keys or indexes.

// Sample JSON data
$jsonData = '{
    "name": "John",
    "age": 30,
    "address": {
        "street": "123 Main St",
        "city": "New York"
    }
}';

// Decode JSON data
$data = json_decode($jsonData, true);

// Access nested data
$street = $data['address']['street'];
$city = $data['address']['city'];

echo "Street: " . $street . "\n";
echo "City: " . $city;