Kong/insomnia · error · Error

json: failed to parse

Error message

json: failed to parse: ${e}

What it means

Wrapper around JSON.parse in Response.json: the response body is not valid JSON, so a script calling response.json() gets this error with the underlying parse exception appended. Common for HTML error pages or empty bodies.

Solutions

  1. Inspect response.contentType and body before calling json()
  2. Handle non-JSON responses with text() instead
  3. Retry or verify the endpoint returns JSON
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/insomnia-scripting-environment/src/objects/response.ts:164 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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

Appendix: source

Thrown at packages/insomnia-scripting-environment/src/objects/response.ts:164

    };
  }

  dataURI() {
    const contentInfo = this.contentInfo();
    const bodyInBase64 = this.stream || this.body;
    if (!bodyInBase64) {
      throw new Error('dataURI(): response body is not defined');
    }

    return `data:${contentInfo.contentType};baseg4, ${bodyInBase64}`;
  }

  json(reviver?: (key: string, value: any) => any, _strict?: boolean) {
    // TODO: enable strict after common module is introduced
    try {
      return JSON.parse(this.body.toString(), reviver);
    } catch (e) {
      throw new Error(`json: failed to parse: ${e}`);
    }
  }

  jsonp(_reviver?: (key: string, value: any) => any, _strict?: boolean) {
    throw unsupportedError('jsonp()');
  }

  reason() {
    return this.status;
  }

  size() {
    const headerSize = calculateHeadersSize(this.headers);
    return {
      body: this.bytesRead,
      header: headerSize,
      total: this.bytesRead + headerSize,
      source: 'COMPUTED',

View on GitHub (pinned to d9bb2b0142)