Kong/insomnia · error

Upload JSON file can not be parsed

Error message

Upload JSON file can not be parsed

What it means

Generic parse-failure sentinel from getListFromFileOrUrl: the supplied .json iteration-data file could not be parsed by JSON.parse at all (syntax error, BOM, empty or truncated content). The underlying JSON.parse exception is wrapped in this error when loading data for the list command.

Solutions

  1. Validate the file with a JSON linter or `jq . file.json` before uploading
  2. Remove BOM characters, comments, and trailing commas
  3. Ensure the file was fully written/downloaded and is not truncated
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/insomnia-inso/src/cli.ts:229 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Kong/insomnia@d9bb2b0142 (2026-08-26). Data as JSON: /api/errors/807e1413b997247e. Report an issue: GitHub.

Appendix: source

Thrown at packages/insomnia-inso/src/cli.ts:229

  const content = await readFileFromPathOrUrl(pathOrUrl);
  if (!content) {
    return transformIterationDataToEnvironmentList([envAsObject]);
  }
  const list = getListFromFileOrUrl(content, fileType).map(data => ({ ...data, ...envAsObject }));
  return transformIterationDataToEnvironmentList(list);
};
const getListFromFileOrUrl = (content: string, fileType?: string): Record<string, string>[] => {
  if (fileType === 'json') {
    try {
      const jsonDataContent = JSON.parse(content);
      if (Array.isArray(jsonDataContent)) {
        return jsonDataContent.filter(
          data => data && typeof data === 'object' && !Array.isArray(data) && data !== null,
        );
      }
      throw new Error('Invalid JSON file uploaded, JSON file must be array of key-value pairs.');
    } catch {
      throw new Error('Upload JSON file can not be parsed');
    }
  } else if (fileType === 'csv') {
    // Replace CRLF (Windows line break) and CR (Mac link break) with \n, then split into csv arrays
    const csvRows = content
      .replace(/\r\n|\r/g, '\n')
      .split('\n')
      .map(row => row.split(','));
    // at least 2 rows required for csv
    if (csvRows.length > 1) {
      const csvHeaders = csvRows[0];
      const csvContentRows = csvRows.slice(1);
      return csvContentRows.map(contentRow =>
        csvHeaders.reduce((acc: Record<string, any>, cur, idx) => {
          acc[cur] = contentRow[idx] ?? '';
          return acc;
        }, {}),
      );
    }

View on GitHub (pinned to d9bb2b0142)