What are the advantages of using JSON files over CSV files in PHP applications?

When working with data in PHP applications, using JSON files can offer several advantages over CSV files. JSON files are more structured and allow for nested data structures, making it easier to represent complex data. Additionally, JSON files support a wider range of data types compared to CSV files. JSON files are also more human-readable and easier to work with programmatically in PHP.

// Reading data from a JSON file
$jsonData = file_get_contents('data.json');
$data = json_decode($jsonData, true);

// Writing data to a JSON file
$newData = ['name' => 'John Doe', 'age' => 30];
$jsonData = json_encode($newData);
file_put_contents('new_data.json', $jsonData);