twentyhq/twenty · error · JsoncParseError
JSONC parse errors:\n${errorMessages.join('\n')}
Error message
JSONC parse errors:\n${errorMessages.join('\n')} What it means
Thrown by parseJsoncString when the jsonc-parser library reports one or more ParseError entries during parsing of a JSONC (JSON with Comments) string. Each error is formatted as 'Line {offset}: {error}' and all errors are joined with newlines. This wraps structured parse errors into a JsoncParseError exception with the underlying ParseError array attached.
Source
Thrown at packages/twenty-sdk/src/cli/utilities/file/file-jsonc.ts:37
}
export const parseJsoncString = (
content: string,
options: JsoncParseOptions = {},
): any => {
const parseErrors: ParseError[] = [];
const result = parseJsonc(content, parseErrors, {
allowTrailingComma: options.allowTrailingComma ?? true,
disallowComments: options.disallowComments ?? false,
allowEmptyContent: options.allowEmptyContent ?? false,
});
if (parseErrors.length > 0) {
const errorMessages = parseErrors.map(
(error) => `Line ${error.offset}: ${error.error}`,
);
throw new JsoncParseError(
`JSONC parse errors:\n${errorMessages.join('\n')}`,
parseErrors,
);
}
return result;
};
export const parseJsoncFile = async <T = object>(
filePath: string,
options: JsoncParseOptions = {},
): Promise<T> => {
try {
const content = await readFile(filePath, 'utf8');
return parseJsoncString(content, options);
} catch (error) {
if (error instanceof JsoncParseError) {
throw new JsoncParseError(error.message, error.parseErrors, filePath);View on GitHub (pinned to 1f5dd2bbd2)
Solutions
- Read the error message — it lists each parse error with its offset and description.
- Open the file in a JSONC-aware editor (VS Code) which will highlight syntax errors visually.
- Validate the file with an online JSONC validator or jsonc-parser directly.
- If the error is about trailing commas, pass { allowTrailingComma: true } to parseJsoncString.
- If the error is about comments, pass { disallowComments: false } (the default) or remove the comments.
Example fix
// before — file has a trailing comma
{ "name": "app", "version": "1.0", }
// after
{ "name": "app", "version": "1.0" } Defensive patterns
Strategy: validation
Validate before calling
import { parse as parseJsonc, type ParseError } from 'jsonc-parser';
const validateJsonc = (content: string): ParseError[] => {
const errors: ParseError[] = [];
parseJsonc(content, errors, { allowTrailingComma: true });
return errors;
};
const errors = validateJsonc(fileContent);
if (errors.length > 0) {
console.error('JSONC errors:', errors.map((e) => `offset ${e.offset}: ${e.error}`));
} Type guard
import { JsoncParseError } from '@/cli/utilities/file/file-jsonc';
const isJsoncParseError = (error: unknown): error is JsoncParseError => {
return error instanceof JsoncParseError;
}; Try / catch
import { JsoncParseError, parseJsoncString } from '@/cli/utilities/file/file-jsonc';
try {
const result = parseJsoncString(content);
} catch (error) {
if (error instanceof JsoncParseError) {
error.parseErrors.forEach((pe) => {
console.error(`Offset ${pe.offset}: ${pe.error}`);
});
return;
}
throw error;
} Prevention
- Use a JSONC-aware editor (VS Code) to catch syntax errors before runtime.
- Validate JSONC files after manual edits with a parser check.
- Pass the appropriate options (allowTrailingComma, disallowComments) matching your file's conventions.
When it happens
Trigger: Calling parseJsoncString(content) where content has syntax errors: unclosed braces/brackets, invalid JSON tokens, trailing commas (if allowTrailingComma is false), or disallowed comments (if disallowComments is true). Empty content when allowEmptyContent is false.
Common situations: A tsconfig.json or other JSONC config file has a typo (missing comma, unclosed bracket). A trailing comma was left in strict mode. A comment was used in a context where comments are disallowed. The file was partially written (interrupted save) leaving truncated JSON.
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
- defineApplication in ${configPath} must declare a universalI
- Failed to read file ${filePath}: ${error}
- Email and password are required
- No date fields for calendar
- File is not valid XML
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/64387127f50384a4.
Report an issue: GitHub.