Visitar URL original
Default reponseType is not `json` · Issue #7253 · axios/axios · GitHub
Skip to content

Default reponseType is not json #7253

Closed

Description

@leozhu7

Describe the bug

In the document, responseType default value is json

  // `responseType` indicates the type of data that the server will respond with
  // options are: 'arraybuffer', 'document', 'json', 'text', 'stream'
  //   browser only: 'blob'
  responseType: 'json', // default

But it is undefined when running axios.
If we do not set it manually, it will prevent throwing a JSON parse error, even if silentJSONParsing is set to false when parsing an unexpected JSON string.

axios/lib/defaults/index.js

Lines 103 to 120 in 8092aee

const JSONRequested = this.responseType === 'json';
if (utils.isResponse(data) || utils.isReadableStream(data)) {
return data;
}
if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
const silentJSONParsing = transitional && transitional.silentJSONParsing;
const strictJSONParsing = !silentJSONParsing && JSONRequested;
try {
return JSON.parse(data, this.parseReviver);
} catch (e) {
if (strictJSONParsing) {
if (e.name === 'SyntaxError') {
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
}
throw e;

It has a similar issue, but does not change it.

since we have gone back and forth a lot on this we will probably not make any new changes till we cut a v1.
Maybe we should fix it in v1.
#3116

I suggest adding a default value in the

const defaults = {
transitional: transitionalDefaults,
adapter: ['xhr', 'http', 'fetch'],

To Reproduce

Set the backend controller to return invalid JSON
Or
Use Fiddler to intercept the response and modify the JSON to invalid JSON.

Code snippet

const response = await axios.get(uri, {
	transitional: { silentJSONParsing: false },
});

Expected behavior

Just set silentJSONParsing as false, when receiving invalid JSON, then throw a JSON parse SyntaxError.

Axios Version

1.13.2

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

Additional context/Screenshots

Image

Activity

  1. id-87 commented on Nov 24, 2025

    @id-87

    @leozhu7 Please assign me this issue

  2. Rudrxxx commented on Nov 24, 2025

    @Rudrxxx
    Contributor

    Hi! @jasonsaayman
    I’ve opened a PR fixing the issue where silentJSONParsing: false did not throw on malformed JSON unless responseType: 'json' was explicitly set.
    The fix corrects the logic in lib/defaults/index.js and includes a regression test to ensure expected behavior.

    Let me know if anything needs adjustment!

  3. added a commit that references this issue on Dec 1, 2025
    905d4bf
  4. added a commit that references this issue on Jan 26, 2026
  5. added 4 commits that reference this issue on Feb 14, 2026
    32d0955
    488077e
    67ef855
    e420901
  6. added a commit that references this issue on Mar 12, 2026
    d4b9357
  7. added a commit that references this issue on Mar 13, 2026
    ebc6056
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions