"Unable to read metadata file."]); exit; } // Decode the JSON data to check for validity $jsonData = json_decode($data, true); if (json_last_error() !== JSON_ERROR_NONE) { error_log('Invalid JSON in metadata file: ' . $metadataPath . ' Error: ' . json_last_error_msg()); http_response_code(500); echo json_encode(["error" => "Metadata file contains invalid JSON."]); exit; } // Output the re-encoded JSON to ensure well-formed output echo json_encode($jsonData); exit;