RocketChat/Rocket.Chat · error · Meteor.Error
Invalid JSON provided
Invalid JSON provided
Error message
Invalid JSON provided
What it means
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.
Source
Thrown at apps/meteor/server/settings/lib/saveSettingsBulk.ts:21
import { Settings } from '@rocket.chat/models';
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { settings } from '..';
import { updateAuditedByUser } from './auditedSettingUpdates';
import { getSettingPermissionId } from '../../../app/authorization/lib';
import { hasPermissionAsync } from '../../lib/authorization/hasPermission';
import { notifyOnSettingChangedById } from '../../lib/notifyListener';
import { validateSettingRules } from '../../lib/settingValidationRules';
import { disableCustomScripts } from '../../lib/shared/disableCustomScripts';
import { checkSettingValueBounds } from '../checkSettingValueBonds';
const validJSON = Match.Where((value: string) => {
try {
value === '' || JSON.parse(value);
return true;
} catch (_) {
throw new Meteor.Error('Invalid JSON provided');
}
});
const checkInteger = (value: ISetting['value']) => {
if (!Number.isInteger(value)) {
throw new Meteor.Error('error-invalid-setting-value', `Invalid setting value ${value}`, {
method: 'saveSettings',
});
}
};
export type SaveSettingsAudit = {
username: string;
ip: string;
useragent: string;
};
export const saveSettingsBulk = async (View on GitHub (pinned to b2c16d5842)
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
Example fix
// before
{ "accounts": [ { "id": 1, }, ], /* trailing comma + comment */ }
// -> Meteor.Error('Invalid JSON provided')
// after
{ "accounts": [ { "id": 1 } ] } Defensive patterns
Strategy: validation
Validate before calling
const canParse = (v: string) => { try { JSON.parse(v); return true; } catch { return false; } };
if (value !== '' && !canParse(value)) {
throw new Error('Fix JSON syntax before saving');
}
Meteor.call('saveSettings', [{ _id: settingId, value }]); Type guard
const isValidJsonSetting = (v: string): boolean =>
v === '' || (() => { try { JSON.parse(v); return true; } catch { return false; } })(); Try / catch
catch (err) {
if (err instanceof Meteor.Error && err.error === 'Invalid JSON provided') {
// re-open the editor, validate with JSON.parse, fix and resubmit
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- error-invalid-setting-value
- error-name-param-not-provided
- error-id-param-not-provided
- message-length-exceeds-character-limit
- The "customFields" query parameter must be a valid JSON.
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/1c3cf4a964b0bc54.
Report an issue: GitHub.