Use json_encode() to send a JSON response from a PHP script, commonly used in AJAX requests.
Source Code
$response = ['status' => 'success', 'message' => 'Data fetched successfully'];
header('Content-Type: application/json');
echo json_encode($response);