{"record":{"id":"8a0bbfaacc23f938","repo":"octobercms/october","slug":"invalid-string-json-object","errorCode":null,"errorMessage":"Invalid string JSON object.","messagePattern":"Invalid string JSON object\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"modules/system/assets/js/framework.js","lineNumber":2070,"sourceCode":"        throw new Error(\"Error parsing the \" + name + \" attribute value. \" + e);\n      }\n    }\n    static parseJSON(json) {\n      return JSON.parse(new _JsonParser().parseString(json));\n    }\n    // Private\n    parseString(str) {\n      str = str.trim();\n      if (!str.length) {\n        throw new Error(\"Broken JSON object.\");\n      }\n      var result = \"\";\n      while (str && str[0] === \",\") {\n        str = str.substr(1);\n      }\n      if (str[0] === '\"' || str[0] === \"'\") {\n        if (str[str.length - 1] !== str[0]) {\n          throw new Error(\"Invalid string JSON object.\");\n        }\n        var body = '\"';\n        for (var i = 1; i < str.length; i++) {\n          if (str[i] === \"\\\\\") {\n            if (str[i + 1] === \"'\") {\n              body += str[i + 1];\n            } else {\n              body += str[i];\n              body += str[i + 1];\n            }\n            i++;\n          } else if (str[i] === str[0]) {\n            body += '\"';\n            return body;\n          } else if (str[i] === '\"') {\n            body += '\\\\\"';\n          } else body += str[i];\n        }","sourceCodeStart":2052,"sourceCodeEnd":2088,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/system/assets/js/framework.js#L2052-L2088","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Close the string with the same quote that opened it: 'hello' or \"hello\"","When embedding the value in markup, prefer double quotes outside and single quotes inside, and keep them balanced","Generate values with JSON.stringify so quoting/escaping is handled correctly","Check for truncation if the tail of the value looks cut off"],"exampleFix":"<!-- before -->\n<div data-request-data=\"'search\">...</div>\n\n<!-- after -->\n<div data-request-data=\"'search'\">...</div>","handlingStrategy":"validation","validationCode":"function quotesTerminate(s) {\n  const t = s.trim();\n  const q = t[0];\n  if (q !== \"'\" && q !== '\"') return true;\n  return t[t.length - 1] === q && t.length >= 2;\n}","typeGuard":null,"tryCatchPattern":"try { const v = oc.parseJSON(raw); } catch (e) { if (/Invalid string JSON object/.test(e.message)) console.error('Unterminated quoted string:', e.message); }","preventionTips":["Open and close string values with the same quote character","Keep attribute delimiters (double quotes) distinct from value quotes (single quotes)","Let JSON.stringify produce the quoting"],"tags":["json","parser","string-literal","quotes","frontend"],"backgroundTag":"unterminated-string-literal","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}