How can i print JSON with console.log

  • A+
Category:Languages

I am writing a program with php laravel and react.js. But i am very new to these. Anyway in react, i am sending a API request with ajax.

like this:

const sendquery = {     "async": true,     "crossDomain": true,     "url": url,     "method": "POST",     "headers": {         "Authorization": "Bearer " + tkid,         "Accept": "application/json",         "Content-Type": "application/json",     },     "processData": false,     "data": query };  $.ajax(sendquery).done(function (response) {     console.log('Survey Request :' + response); }); 

There are another API requests that are printing nicely when i console.log() because they are in array type. But this must be json. I tested API with Postman everything is OK. But still i have output like this:

Survey Request :[object Object] 

Can you please help ?

 


You can try with JSON.stringify(response) but note that it doesn't work with all the types, see JSON.stringify doesn't work with normal Javascript array, for example.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: