Skip to content

Passing ResponseType of 'json' to get() no longer parses the JSON in v0.21.4 #5853

@HTcbaldwin

Description

@HTcbaldwin

Describe the bug

If you pass a response type of 'json' with a get request, it should automagically return the response.data as a parsed JSON object. Currently it comes back as a JSON string like if you set the ResponseType to 'text'.

image

To Reproduce

Call an API endpoint that returns JSON, and set the responseType on the get request to 'json'.

Code snippet

const instance = axios.create({
  baseURL: '/api',
  transformResponse: responseTransformer,
  responseType: 'json',
});

const response = await instance.get("my/endpoint", { responseType: 'json' });

typeof response === 'string' // true

Expected behavior

In version 0.21.1, the requests were being parsed correctly, and I was getting a JS object back.

Axios Version

0.21.4

Adapter Version

No response

Browser

Chrome

Browser Version

116.0.5845.140

Node.js Version

14.19.3

OS

Fedora 37

Additional Library Versions

No response

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