Home > Back-end >  Transform AxiosResponse to String
Transform AxiosResponse to String

Time:06-18

My application calls an API using axios.get, like below. Is there a way to console.log r and r.data so I can view it as a string?

const r = await axios.get(k);

CodePudding user response:

If I understood well what you need, you could use JSON.stringify(), like so:

const r = await axios.get(k);
console.log(JSON.stringify(r));
console.log(JSON.stringify(r.data));

CodePudding user response:

If the response is a JSON object, you can just use JSON.stringify() to get the response data as a string.

const r = await axios.get(k);
const stringResponse = JSON.stringify(r)
  • Related