louislam/uptime-kuma · error · Error

Your JSON body is invalid. ${e.message}

Error message

Your JSON body is invalid. ${e.message}

What it means

Thrown by an HTTP/HTTPS monitor when HTTP Body Encoding is 'json' (the default when unset) and the configured request body fails JSON.parse. Uptime Kuma parses this.body into a JS object so axios can send it as application/json; any JSON syntax error aborts the beat and marks it DOWN.

Source

Thrown at server/model/monitor.js:546

                    const httpAgentOptions = {
                        maxCachedSessions: 0,
                        autoSelectFamily: true,
                        ...(agentFamily ? { family: agentFamily } : {}),
                    };

                    log.debug("monitor", `[${this.name}] Prepare Options for axios`);

                    let contentType = null;
                    let bodyValue = null;

                    if (this.body && typeof this.body === "string" && this.body.trim().length > 0) {
                        if (!this.httpBodyEncoding || this.httpBodyEncoding === "json") {
                            try {
                                bodyValue = JSON.parse(this.body);
                                contentType = "application/json";
                            } catch (e) {
                                throw new Error("Your JSON body is invalid. " + e.message);
                            }
                        } else if (this.httpBodyEncoding === "form") {
                            bodyValue = this.body;
                            contentType = "application/x-www-form-urlencoded";
                        } else if (this.httpBodyEncoding === "xml") {
                            bodyValue = this.body;
                            contentType = "text/xml; charset=utf-8";
                        }
                    }

                    // Axios Options
                    const options = {
                        url: this.url,
                        method: (this.method || "get").toLowerCase(),
                        timeout: this.timeout * 1000,
                        headers: {
                            Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
                            ...(contentType ? { "Content-Type": contentType } : {}),

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Run JSON.parse on the body in a JS console before saving to locate the exact syntax error
  2. If the body is not JSON, set HTTP Body Encoding to 'form' or 'xml' in the monitor settings
  3. Escape embedded quotes and newlines inside string values
  4. Re-type quotes manually instead of pasting to avoid smart/curly quotes

Example fix

// before
this.body = "{'name': 'kuma',}";

// after
this.body = '{"name":"kuma"}';
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check a JSON body before saving the HTTP monitor
function assertJsonBody(body, encoding) {
  if (!body || (encoding && encoding !== "json")) return; // not in json mode
  try {
    JSON.parse(body);
  } catch (e) {
    throw new Error(`Body is not valid JSON: ${e.message}`);
  }
}

Type guard

// Confirm body parses to an object/array (json encoding only)
function isValidJsonBody(body, encoding) {
  if (!body || (encoding && encoding !== "json")) return true;
  try {
    const v = JSON.parse(body);
    return typeof v === "object" && v !== null;
  } catch {
    return false;
  }
}

Prevention

When it happens

Trigger: Saving an HTTP monitor with a non-empty body while httpBodyEncoding is unset or 'json', and the body string is not valid JSON (trailing comma, single quotes, unescaped newline, comments, smart quotes).

Common situations: Pasting JSON copied from docs/chat that introduced curly quotes; copy-paste leaving a trailing comma; user intends form-urlencoded but left encoding on the default 'json'.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/e2626c49d8894fc4. Report an issue: GitHub.