How to read JSON response with Axios and JavaScript?

Sometimes, we want to read JSON response with Axios and JavaScript.

In this article, we’ll look at how to read JSON response with Axios and JavaScript.

How to read JSON response with Axios and JavaScript?

To read JSON response with Axios and JavaScript, we get the response body from the data property.

For instance, we write

try {
  const res = await axios.get("/end-point");
  console.log(res.data);
} catch (error) {
  // ...
}

to call axios.get to make a get request.

It returns a promise that has the response data.

We get the response body from res.data.

Conclusion

To read JSON response with Axios and JavaScript, we get the response body from the data property.