{"record":{"id":"2ccb85e7871c94c2","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-customfield-json-2ccb85","errorCode":"error-invalid-customfield-json","errorMessage":"Invalid JSON for Custom Fields","messagePattern":"Invalid JSON for Custom Fields","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/validateCustomFields.js","lineNumber":17,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { trim } from '../../../lib/utils/stringUtils';\nimport { settings } from '../../settings';\n\nexport const validateCustomFields = function (fields) {\n\t// Special Case:\n\t// If an admin didn't set any custom fields there's nothing to validate against so consider any customFields valid\n\tif (trim(settings.get('Accounts_CustomFields')) === '') {\n\t\treturn;\n\t}\n\n\tlet customFieldsMeta;\n\ttry {\n\t\tcustomFieldsMeta = JSON.parse(settings.get('Accounts_CustomFields'));\n\t} catch (e) {\n\t\tthrow new Meteor.Error('error-invalid-customfield-json', 'Invalid JSON for Custom Fields');\n\t}\n\n\tconst customFields = {};\n\n\tObject.keys(customFieldsMeta).forEach((fieldName) => {\n\t\tconst field = customFieldsMeta[fieldName];\n\n\t\tcustomFields[fieldName] = fields[fieldName];\n\t\tconst fieldValue = trim(fields[fieldName]);\n\n\t\tif (field.required && fieldValue === '') {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Field ${fieldName} is required`, { method: 'registerUser' });\n\t\t}\n\n\t\tif (field.type === 'select' && field.options.indexOf(fields[fieldName]) === -1) {\n\t\t\tthrow new Meteor.Error('error-user-registration-custom-field', `Value for field ${fieldName} is invalid`, { method: 'registerUser' });\n\t\t}\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/validateCustomFields.js#L1-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix Accounts_CustomFields in Administration > Accounts > Custom Fields; validate the string in a JSON linter before saving","Add a guard that JSON.parse's the setting value on save (settings-watched job or admin hook) so mistakes surface immediately","In code calling validateCustomFields, catch error-invalid-customfield-json and surface 'custom fields misconfigured — contact admin' instead of a generic failure"],"exampleFix":"// before (bad setting value)\n{ 'department': { type: 'select' }, }  // single quotes + trailing comma -> JSON.parse fails\n\n// after\n{\"department\":{\"type\":\"select\",\"options\":[\"sales\",\"eng\"]}}","handlingStrategy":"validation","validationCode":"const raw = String(settings.get('Accounts_CustomFields') ?? '').trim();\nif (raw !== '') {\n  try {\n    JSON.parse(raw); // healthy\n  } catch {\n    // setting broken: disable the custom-fields form and alert admins\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  validateCustomFields(fields);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-invalid-customfield-json') {\n    // workspace misconfiguration: surface 'invalid custom fields config' to an admin\n  } else {\n    throw error;\n  }\n}","preventionTips":["Lint the custom-fields JSON in a validator before pasting into settings","Never use single quotes or trailing commas; quote every key","Check this setting first when all custom-field saves start failing at once"],"tags":["custom-fields","json","settings","configuration","meteor"],"backgroundTag":"invalid-json-config","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"}