octobercms/october · error · Error
Broken JSON boolean body near ${str}
Error message
Broken JSON boolean body near ${str} What it means
Part of the same lenient JSON scanner: getBody() dispatches on the first character of a value, so any unquoted token starting with 't' is assumed to be the boolean literal true. If the next four characters are not exactly "true" (e.g. "tru", "ture", "trueX", "test"), the parser throws this error. It fires during oc.parseJSON, i.e. whenever a data-* attribute like data-request-data is parsed.
Source
Thrown at modules/system/assets/js/framework.js:2226
i++;
} else if (str[i] === str[pos]) {
body += str[pos];
return {
originLength: body.length,
body
};
} else body += str[i];
}
throw new Error("Broken JSON string body near " + body);
}
if (str[pos] === "t") {
if (str.indexOf("true", pos) === pos) {
return {
originLength: "true".length,
body: "true"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));
}
if (str[pos] === "f") {
if (str.indexOf("f", pos) === pos) {
return {
originLength: "false".length,
body: "false"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));
}
if (str[pos] === "n") {
if (str.indexOf("null", pos) === pos) {
return {
originLength: "null".length,
body: "null"
};
}
throw new Error("Broken JSON boolean body near " + str.substr(0, pos + 10));View on GitHub (pinned to b608633a7e)
Solutions
- Quote the string value if it is text: {filter: 'today'} or filter: "today".
- If a boolean was intended, correct the spelling to the exact lowercase literal true.
- Remember the rule: only bare true/false/null are allowed unquoted; everything else must be quoted.
Example fix
// before
<a data-request="onFilter" data-request-data="filter: today">Today</a>
// after
<a data-request="onFilter" data-request-data="{filter: 'today'}">Today</a> Defensive patterns
Strategy: validation
Validate before calling
// Allow only true/false/null unquoted; everything else must be quoted
function validBareTokens(value) {
return value.replace(/'[^']*'|"[^"]*"/g, '').match(/:(?:\s*)(t(?!rue\b)|f(?!alse\b)|n(?!ull\b))\w/i) === null;
} Try / catch
try { oc.parseJSON(raw); } catch (e) { /* treat attribute as absent and log */ console.warn('Ignoring malformed config:', e.message); } Prevention
- Adopt the rule 'only true/false/null go bare' in code review for markup.
- Prefer fully JSON (quoted keys and strings) in generated markup; keep the lenient syntax only for hand-written shorthand.
- When a value starts with t/f/n and is text, quote it.
When it happens
Trigger: An unquoted string value starting with t: data-request-data="filter: today" (wrapped to {filter: today}); a boolean typo such as {enabled: ture} or {flag: tru}; a capitalized boolean {ok: True} does NOT hit this branch (it falls through to the generic 'Broken JSON body' error) — only lowercase t-prefixed tokens do.
Common situations: Authors writing shorthand attribute configs (key: value) and forgetting quotes around text values; booleans mistyped; migrating jQuery-era inline options into data attributes.
Related errors
- Broken JSON string body near ${body}
- Broken JSON number body near ${body}
- Broken JSON ${str[pos] === "{" ? "object" : "array"} body ne
- Broken JSON body near ${str}
- Broken JSON boolean body near ${str}
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/f57284f32c0953de.
Report an issue: GitHub.