{"record":{"id":"1c3cf4a964b0bc54","repo":"RocketChat/Rocket.Chat","slug":"invalid-json-provided","errorCode":"Invalid JSON provided","errorMessage":"Invalid JSON provided","messagePattern":"Invalid JSON provided","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/settings/lib/saveSettingsBulk.ts","lineNumber":21,"sourceCode":"import { Settings } from '@rocket.chat/models';\nimport { Match, check } from 'meteor/check';\nimport { Meteor } from 'meteor/meteor';\n\nimport { settings } from '..';\nimport { updateAuditedByUser } from './auditedSettingUpdates';\nimport { getSettingPermissionId } from '../../../app/authorization/lib';\nimport { hasPermissionAsync } from '../../lib/authorization/hasPermission';\nimport { notifyOnSettingChangedById } from '../../lib/notifyListener';\nimport { validateSettingRules } from '../../lib/settingValidationRules';\nimport { disableCustomScripts } from '../../lib/shared/disableCustomScripts';\nimport { checkSettingValueBounds } from '../checkSettingValueBonds';\n\nconst validJSON = Match.Where((value: string) => {\n\ttry {\n\t\tvalue === '' || JSON.parse(value);\n\t\treturn true;\n\t} catch (_) {\n\t\tthrow new Meteor.Error('Invalid JSON provided');\n\t}\n});\n\nconst checkInteger = (value: ISetting['value']) => {\n\tif (!Number.isInteger(value)) {\n\t\tthrow new Meteor.Error('error-invalid-setting-value', `Invalid setting value ${value}`, {\n\t\t\tmethod: 'saveSettings',\n\t\t});\n\t}\n};\n\nexport type SaveSettingsAudit = {\n\tusername: string;\n\tip: string;\n\tuseragent: string;\n};\n\nexport const saveSettingsBulk = async (","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/settings/lib/saveSettingsBulk.ts#L3-L39","documentation":"During saveSettingsBulk, settings of type 'code' whose code property is 'application/json' are validated with JSON.parse; if parsing throws, the save fails with Meteor error 'Invalid JSON provided' (the error string doubles as the code). Only the 'does JSON.parse throw' behavior matters - an empty string passes, and any trailing comma, comment, single-quoted string, or unquoted key fails.","triggerScenarios":"Pasting JSON with JS-only syntax (comments, trailing commas) into a JSON code setting in the admin UI; REST callers submitting a malformed string for an application/json setting; saving a half-edited JSON blob where syntax is temporarily broken.","commonSituations":"Admins treating a JSON setting as a JS/JSON5 file; copy-paste from blog posts or other tools using different dialects; quote-escaping broken by nested pasting into a text field.","solutions":["Run JSON.parse (or a JSON linter) on the value before saving and fix the syntax errors","Remove comments, trailing commas and single quotes; double-quote all keys and strings","Send an empty string if the setting should be cleared - empty is explicitly allowed","Use a JSON-aware editor in the admin UI so mistakes surface before submit"],"exampleFix":"// before\n{ \"accounts\": [ { \"id\": 1, }, ], /* trailing comma + comment */ }\n// -> Meteor.Error('Invalid JSON provided')\n\n// after\n{ \"accounts\": [ { \"id\": 1 } ] }","handlingStrategy":"validation","validationCode":"const canParse = (v: string) => { try { JSON.parse(v); return true; } catch { return false; } };\nif (value !== '' && !canParse(value)) {\n\tthrow new Error('Fix JSON syntax before saving');\n}\nMeteor.call('saveSettings', [{ _id: settingId, value }]);","typeGuard":"const isValidJsonSetting = (v: string): boolean =>\n\tv === '' || (() => { try { JSON.parse(v); return true; } catch { return false; } })();","tryCatchPattern":"catch (err) {\n\tif (err instanceof Meteor.Error && err.error === 'Invalid JSON provided') {\n\t\t// re-open the editor, validate with JSON.parse, fix and resubmit\n\t} else throw err;\n}","preventionTips":["Use a JSON-aware editor for application/json settings","Never paste comments or trailing commas into JSON settings","Validate with JSON.parse before every programmatic save"],"tags":["settings","json","validation","admin","code-setting"],"backgroundTag":"invalid-json","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}