{"record":{"id":"0690ec51315b403c","repo":"RocketChat/Rocket.Chat","slug":"the-json-specified-for-accounts-customfields-is","errorCode":null,"errorMessage":"The JSON specified for \"Accounts_CustomFields\" is invalid. The following error was thrown","messagePattern":"The JSON specified for \"Accounts_CustomFields\" is invalid\\. The following error was thrown","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/users/getFullUserData.ts","lineNumber":68,"sourceCode":"\tpublicCustomFields = {};\n\tcustomFields = {};\n\n\tconst value = settingValue?.trim();\n\tif (!value) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst customFieldsOnServer = JSON.parse(value);\n\t\tObject.keys(customFieldsOnServer).forEach((key) => {\n\t\t\tconst element = customFieldsOnServer[key];\n\t\t\tif (element.public) {\n\t\t\t\tpublicCustomFields[`customFields.${key}`] = 1;\n\t\t\t}\n\t\t\tcustomFields[`customFields.${key}`] = 1;\n\t\t});\n\t} catch (e) {\n\t\tlogger.warn({\n\t\t\tmsg: 'The JSON specified for \"Accounts_CustomFields\" is invalid. The following error was thrown',\n\t\t\terr: e,\n\t\t});\n\t}\n});\n\nconst getCustomFields = (canViewAllInfo: boolean): Record<string, 0 | 1> => (canViewAllInfo ? customFields : publicCustomFields);\n\nconst getFields = (canViewAllInfo: boolean): Record<string, 0 | 1> => ({\n\t...defaultFields,\n\t...(canViewAllInfo && fullFields),\n\t...getCustomFields(canViewAllInfo),\n});\n\nconst findTargetUser = (type: string, value: string, opts: any) => {\n\tif (type === 'importId') return Users.findOneByImportId(value, opts);\n\tif (type === 'email') return Users.findOneByEmailAddress(value, opts);\n\tif (type === 'freeSwitchExtension') return Users.findOneByFreeSwitchExtension(value, opts);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/2a7de457074cbb4d4373fbd9a4e5bea292c9c764/apps/meteor/server/lib/users/getFullUserData.ts#L50-L86","documentation":"A settings watcher builds MongoDB field projections for user data from the Accounts_CustomFields setting: it JSON.parses the value and maps each custom field into publicCustomFields/customCustomFields projections. On parse failure it only logs this warning and keeps the previously computed projections (empty on first run) — the visible symptom is custom fields silently missing from user data / REST API responses even though the raw setting still contains the invalid JSON.","triggerScenarios":"Same root cause as the 'Invalid Custom Fields' warn from the API layer: Accounts_CustomFields saved as invalid JSON (trailing commas, single quotes, unquoted keys, truncated value). Fires whenever the watcher recomputes after such a save.","commonSituations":"Pasted JSON with syntax errors; env-deployed settings with mangled escaping; symptom noticed as customFields absent from users.info / full user data API responses.","solutions":["Fix the JSON in Accounts_CustomFields (validate with jsonlint) and save — the watcher recomputes projections immediately","Cross-check the server logs for the companion 'Invalid Custom Fields' warn from the API layer; both share the root cause","Prevent recurrence by validating the JSON in CI when deploying settings via env/infrastructure tooling"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function parseCustomFields(value: string): Record<string, { public?: boolean }> | null {\n\ttry {\n\t\treturn JSON.parse(value);\n\t} catch {\n\t\treturn null;\n\t}\n}\n// null means: keep previous projections and alert the admin, do not silently drop fields","typeGuard":null,"tryCatchPattern":"try {\n\tconst customFieldsOnServer = JSON.parse(value);\n\t/* build projections */\n} catch (e) {\n\tlogger.warn({ msg: 'The JSON specified for \"Accounts_CustomFields\" is invalid. The following error was thrown', err: e });\n\t// projections stay at their previous state on purpose\n}","preventionTips":["Validate Accounts_CustomFields JSON before saving, in the UI and in deployment pipelines","When custom fields vanish from API responses, check this warn first — it is the usual cause","Fix the value once; both the API watcher and this projection watcher recover together"],"tags":["settings","json","custom-fields","rest-api","mongodb-projection"],"backgroundTag":"invalid-json-config","analyzedSha":"2a7de457074cbb4d4373fbd9a4e5bea292c9c764","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}