{"record":{"id":"7106589df57b6f83","repo":"louislam/uptime-kuma","slug":"headers-must-be-valid-json-e-message","errorCode":null,"errorMessage":"Headers must be valid JSON: ${e.message}","messagePattern":"Headers must be valid JSON: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/model/monitor.js","lineNumber":1681,"sourceCode":"                JSON.parse(this.rabbitmqNodes);\n            } catch (e) {\n                throw new Error(`RabbitMQ Nodes must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.conditions) {\n            try {\n                JSON.parse(this.conditions);\n            } catch (e) {\n                throw new Error(`Conditions must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.headers) {\n            try {\n                JSON.parse(this.headers);\n            } catch (e) {\n                throw new Error(`Headers must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.accepted_statuscodes_json) {\n            try {\n                JSON.parse(this.accepted_statuscodes_json);\n            } catch (e) {\n                throw new Error(`Accepted status codes must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if ([\"system-service\", \"pm2\"].includes(this.type)) {\n            this.system_service_name = (this.system_service_name || \"\").trim();\n\n            if (!this.system_service_name) {\n                throw new Error(this.type === \"pm2\" ? \"PM2 process name is required.\" : \"Service Name is required.\");\n            }\n        }","sourceCodeStart":1663,"sourceCodeEnd":1699,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/model/monitor.js#L1663-L1699","documentation":"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\"}).","triggerScenarios":"headers is not a valid JSON object, e.g. raw 'Authorization: Bearer x' curl-style lines pasted in, or unescaped newlines.","commonSituations":"Pasting curl -H lines instead of a JSON object; multi-line header text with real newlines breaking JSON.","solutions":["Provide headers as a JSON object: {\"key\":\"value\"}","Escape any newlines inside header values and validate with JSON.parse before saving"],"exampleFix":"// before\nmonitor.headers = \"Authorization: Bearer X\";\n\n// after\nmonitor.headers = '{\"Authorization\":\"Bearer X\"}';","handlingStrategy":"validation","validationCode":"if (monitor.headers) {\n  const v = JSON.parse(monitor.headers);\n  if (typeof v !== \"object\" || v === null || Array.isArray(v)) throw new Error(\"headers must be a JSON object\");\n}","typeGuard":"function isValidHeaders(v) {\n  if (!v) return true;\n  try { const o = JSON.parse(v); return o && typeof o === \"object\" && !Array.isArray(o); }\n  catch { return false; }\n}","tryCatchPattern":"try { monitor.validate(); await save(monitor); } catch (e) { /* surface e.message */ }","preventionTips":["Convert curl -H lines to a JSON object before pasting","Escape newlines inside header values"],"tags":["json","validation","config","headers","http"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}