RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-customfield-json

error-invalid-customfield-json

Error message

Invalid JSON for Custom Fields

What it means

validateCustomFields JSON.parse()s the Accounts_CustomFields setting; when the setting is non-empty but not valid JSON it throws error-invalid-customfield-json. The setting is only parsed when a registration/profile save validates custom fields, so one bad admin edit breaks every such save until the setting is corrected.

Source

Thrown at apps/meteor/server/lib/users/validateCustomFields.js:17

import { Meteor } from 'meteor/meteor';

import { trim } from '../../../lib/utils/stringUtils';
import { settings } from '../../settings';

export const validateCustomFields = function (fields) {
	// Special Case:
	// If an admin didn't set any custom fields there's nothing to validate against so consider any customFields valid
	if (trim(settings.get('Accounts_CustomFields')) === '') {
		return;
	}

	let customFieldsMeta;
	try {
		customFieldsMeta = JSON.parse(settings.get('Accounts_CustomFields'));
	} catch (e) {
		throw new Meteor.Error('error-invalid-customfield-json', 'Invalid JSON for Custom Fields');
	}

	const customFields = {};

	Object.keys(customFieldsMeta).forEach((fieldName) => {
		const field = customFieldsMeta[fieldName];

		customFields[fieldName] = fields[fieldName];
		const fieldValue = trim(fields[fieldName]);

		if (field.required && fieldValue === '') {
			throw new Meteor.Error('error-user-registration-custom-field', `Field ${fieldName} is required`, { method: 'registerUser' });
		}

		if (field.type === 'select' && field.options.indexOf(fields[fieldName]) === -1) {
			throw new Meteor.Error('error-user-registration-custom-field', `Value for field ${fieldName} is invalid`, { method: 'registerUser' });
		}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Fix Accounts_CustomFields in Administration > Accounts > Custom Fields; validate the string in a JSON linter before saving
  2. Add a guard that JSON.parse's the setting value on save (settings-watched job or admin hook) so mistakes surface immediately
  3. In code calling validateCustomFields, catch error-invalid-customfield-json and surface 'custom fields misconfigured — contact admin' instead of a generic failure

Example fix

// before (bad setting value)
{ 'department': { type: 'select' }, }  // single quotes + trailing comma -> JSON.parse fails

// after
{"department":{"type":"select","options":["sales","eng"]}}
Defensive patterns

Strategy: validation

Validate before calling

const raw = String(settings.get('Accounts_CustomFields') ?? '').trim();
if (raw !== '') {
  try {
    JSON.parse(raw); // healthy
  } catch {
    // setting broken: disable the custom-fields form and alert admins
  }
}

Try / catch

try {
  validateCustomFields(fields);
} catch (error) {
  if (error instanceof Meteor.Error && error.error === 'error-invalid-customfield-json') {
    // workspace misconfiguration: surface 'invalid custom fields config' to an admin
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: An admin saves Accounts_CustomFields containing a trailing comma, single quotes, unquoted keys, or smart quotes pasted from documentation; the raw string then fails JSON.parse at validateCustomFields.js:15-17.

Common situations: Copy/pasting field definitions from blog posts or chat (smart quotes are invisible); provisioning the setting via env vars or instance export where escaping is lost; partial edits leaving unbalanced braces.

Understand the failure class

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/2ccb85e7871c94c2. Report an issue: GitHub.