How can JSON be used effectively to store and retrieve data in PHP scripts?

JSON can be effectively used to store and retrieve data in PHP scripts by encoding PHP data structures into JSON format using the `json_encode()` function and decoding JSON data back into PHP data structures using the `json_decode()` function. This allows for easy serialization and deserialization of data, making it simple to store and retrieve complex data structures in a readable and portable format.

// Storing data in JSON format
$data = array('name' => 'John Doe', 'age' => 30);
$jsonData = json_encode($data);
file_put_contents('data.json', $jsonData);

// Retrieving data from JSON format
$jsonData = file_get_contents('data.json');
$data = json_decode($jsonData, true);
echo $data['name']; // Output: John Doe
echo $data['age']; // Output: 30