What are the best practices for passing HTML code as JSON in PHP functions?

When passing HTML code as JSON in PHP functions, it's important to properly encode the HTML content to prevent any syntax errors or data corruption. One common approach is to use the `json_encode` function to encode the HTML content before passing it as JSON. This ensures that the HTML code is properly formatted and can be decoded correctly when retrieved.

$html = '<div><h1>Hello, World!</h1></div>';

// Encode HTML content as JSON
$encoded_html = json_encode($html);

// Pass the encoded HTML content as JSON to a PHP function
your_function($encoded_html);