DEV Community

Cover image for response.json is not a function TypeError
Aishanii
Aishanii

Posted on

5 3

response.json is not a function TypeError

If you are using fetch

The fetch() method returns a Promise that response to a Response object. The json() method basically parses the response for JSON which is then changed to a native JavaScript object.

Use the json method on response with correct call to fetch.

useEffect(() => {
    fetch("https://jsonplaceholder.typicode.com/todos")
      .then((response) => response.json())
      .then((data) => {
       console.log(data)
       }
 }));
Enter fullscreen mode Exit fullscreen mode

If you are using axios

Axios keeps parsing the response in check, so we just look into the data property of response as it contains the data sent from the server.

import axios from 'axios';

useEffect(() => {
    axios.get("https://jsonplaceholder.typicode.com/todos")
    .then((response) => {
        const ex = response.data.json();
        console.log(ex);
     });
}
Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay