louislam/uptime-kuma · error · Error

Headers must be valid JSON: ${e.message}

Error message

Headers must be valid JSON: ${e.message}

What it means

validate() runs JSON.parse on the headers field for HTTP monitors. It must be a JSON object mapping header names to values (e.g. {"Authorization":"Bearer x"}).

Source

Thrown at server/model/monitor.js:1681

                JSON.parse(this.rabbitmqNodes);
            } catch (e) {
                throw new Error(`RabbitMQ Nodes must be valid JSON: ${e.message}`);
            }
        }

        if (this.conditions) {
            try {
                JSON.parse(this.conditions);
            } catch (e) {
                throw new Error(`Conditions must be valid JSON: ${e.message}`);
            }
        }

        if (this.headers) {
            try {
                JSON.parse(this.headers);
            } catch (e) {
                throw new Error(`Headers must be valid JSON: ${e.message}`);
            }
        }

        if (this.accepted_statuscodes_json) {
            try {
                JSON.parse(this.accepted_statuscodes_json);
            } catch (e) {
                throw new Error(`Accepted status codes must be valid JSON: ${e.message}`);
            }
        }

        if (["system-service", "pm2"].includes(this.type)) {
            this.system_service_name = (this.system_service_name || "").trim();

            if (!this.system_service_name) {
                throw new Error(this.type === "pm2" ? "PM2 process name is required." : "Service Name is required.");
            }
        }

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Provide headers as a JSON object: {"key":"value"}
  2. Escape any newlines inside header values and validate with JSON.parse before saving

Example fix

// before
monitor.headers = "Authorization: Bearer X";

// after
monitor.headers = '{"Authorization":"Bearer X"}';
Defensive patterns

Strategy: validation

Validate before calling

if (monitor.headers) {
  const v = JSON.parse(monitor.headers);
  if (typeof v !== "object" || v === null || Array.isArray(v)) throw new Error("headers must be a JSON object");
}

Type guard

function isValidHeaders(v) {
  if (!v) return true;
  try { const o = JSON.parse(v); return o && typeof o === "object" && !Array.isArray(o); }
  catch { return false; }
}

Try / catch

try { monitor.validate(); await save(monitor); } catch (e) { /* surface e.message */ }

Prevention

When it happens

Trigger: headers is not a valid JSON object, e.g. raw 'Authorization: Bearer x' curl-style lines pasted in, or unescaped newlines.

Common situations: Pasting curl -H lines instead of a JSON object; multi-line header text with real newlines breaking JSON.

Related errors


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