A “malformed JSON” error usually means the API request body is not valid JSON. When converting HTML to PDF, a common cause is an unescaped double quotation mark inside the html string.
Recommended: let your tool build the JSON
In the PDF.co Make module, paste or map the HTML into the Input HTML Code field. Do not wrap that field value in a JSON object.
If your HTTP tool provides structured JSON fields, supply the HTML as the value of the html field and let the tool encode the request. If you enter a raw JSON body instead, follow the escaping examples below.
When your code builds the request, use JSON.stringify() in JavaScript or json.dumps() in Python to encode the request object. This handles quotation marks, backslashes, and line breaks without changing your HTML.
JavaScript
const html = '<p>He said "Hello".</p>';
const body = JSON.stringify({ html });Python
import json
html = '<p>He said "Hello".</p>'
body = json.dumps({"html": html})These examples build the request body; they do not send it. Encode the request once. If your HTTP library accepts an object through a JSON option, pass the object to that option instead of encoding it first.
When entering a raw JSON body
JSON property names and string values must use double quotes. A double quote inside a string must be escaped as \".
Incorrect — intentionally invalid JSON
{
"html": "<p>He said "Hello".</p>"
}Correct — escape the quotation marks inside the HTML text
{
"html": "<p>He said \"Hello\".</p>"
}Correct — escape double quotes around HTML attribute values
{
"html": "<a href=\"https://pdf.co\">PDF.co</a>"
}Alternative: single quotes around HTML attributes
HTML attribute values can use single quotes. Keep double quotes around JSON property names and string values:
{
"html": "<a href='https://pdf.co'>PDF.co</a>"
}Change only the relevant HTML attribute delimiters. Do not replace every quotation mark in a complete HTML document, because this may change text, scripts, or other content.
Quotation marks in HTML text
For quotation marks in HTML text, " is also valid. It is an HTML character reference that renders as a quotation mark:
{
"html": "<p>He said "Hello".</p>"
}This is different from JSON escaping. It is an option for HTML content, not a replacement for encoding the JSON request correctly. Do not encode the entire HTML document as text.
Check the request before retrying
Validate the final raw request body as JSON, including any mapped values.
Use straight double quotes for JSON syntax, with no trailing commas.
Set
Content-Type: application/jsonwhen sending a JSON request directly.If the error continues, share the platform, exact error message, and a sample request with your API key and private information removed.