octobercms/october · error · Error

Invalid string JSON object.

Error message

Invalid string JSON object.

What it means

First 'Invalid string JSON object' throw in JsonParser.parseString (October CMS AJAX framework). When the trimmed input starts with a quote (' or "), the parser requires the last character to be the same quote - a cheap well-formedness check before scanning. If the string is not terminated by a matching quote at the end, this error is thrown immediately.

Source

Thrown at modules/system/assets/js/framework.js:2070

        throw new Error("Error parsing the " + name + " attribute value. " + e);
      }
    }
    static parseJSON(json) {
      return JSON.parse(new _JsonParser().parseString(json));
    }
    // Private
    parseString(str) {
      str = str.trim();
      if (!str.length) {
        throw new Error("Broken JSON object.");
      }
      var result = "";
      while (str && str[0] === ",") {
        str = str.substr(1);
      }
      if (str[0] === '"' || str[0] === "'") {
        if (str[str.length - 1] !== str[0]) {
          throw new Error("Invalid string JSON object.");
        }
        var body = '"';
        for (var i = 1; i < str.length; i++) {
          if (str[i] === "\\") {
            if (str[i + 1] === "'") {
              body += str[i + 1];
            } else {
              body += str[i];
              body += str[i + 1];
            }
            i++;
          } else if (str[i] === str[0]) {
            body += '"';
            return body;
          } else if (str[i] === '"') {
            body += '\\"';
          } else body += str[i];
        }

View on GitHub (pinned to b608633a7e)

Solutions

  1. Close the string with the same quote that opened it: 'hello' or "hello"
  2. When embedding the value in markup, prefer double quotes outside and single quotes inside, and keep them balanced
  3. Generate values with JSON.stringify so quoting/escaping is handled correctly
  4. Check for truncation if the tail of the value looks cut off

Example fix

<!-- before -->
<div data-request-data="'search">...</div>

<!-- after -->
<div data-request-data="'search'">...</div>
Defensive patterns

Strategy: validation

Validate before calling

function quotesTerminate(s) {
  const t = s.trim();
  const q = t[0];
  if (q !== "'" && q !== '"') return true;
  return t[t.length - 1] === q && t.length >= 2;
}

Try / catch

try { const v = oc.parseJSON(raw); } catch (e) { if (/Invalid string JSON object/.test(e.message)) console.error('Unterminated quoted string:', e.message); }

Prevention

When it happens

Trigger: oc.parseJSON("'hello") (closing single quote missing); oc.parseJSON('"hello\'') with mismatched quote styles at the ends; attribute values handed in with the tail quote lost to truncation or template interpolation.

Common situations: Truncation of quoted values (length limits, cut-off copy-paste); mixing ' and " around one value; template output dropping the final quote; values that legitimately contain the quote char unescaped at the end.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/8a0bbfaacc23f938. Report an issue: GitHub.