Yes, you can use json_encode
to take your HTML string and escape it as necessary.
Note that in JSON, the top level item must be an array or object (that's not true anymore), it cannot just be a string. So you'll want to create an object and make the HTML string a property of the object (probably the only one), so the resulting JSON looks something like:
{"html": "<p>I'm the markup</p>"}