What are the potential benefits and drawbacks of using PHP to generate JSON for displaying data in HTML?

When using PHP to generate JSON for displaying data in HTML, some potential benefits include easier data manipulation and organization, as well as the ability to dynamically update content without reloading the page. However, drawbacks may include increased server load and potential security vulnerabilities if not properly sanitized.

<?php
// Sample code to generate JSON data in PHP

$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'john.doe@example.com'
);

header('Content-Type: application/json');
echo json_encode($data);
?>