SyntaxError: Unexpected end of JSON input in fetch api

Viewed 152

if i do this->

fetch(
      //something,
      options
    )
      .then((response) => response.json() )  

it gives me error 'SyntaxError: Unexpected end of JSON input in fetch api' but if i remove .json() after response like->

fetch(
      //something,
      options
    )
      .then((response) => response )

it stops throwing error. can anyone explain me the issue

1 Answers

as @iLittleWizard and @derpirscher said in the comment,

try

fetch(
      //something,
      options
    )
    .then(response=> response.text()).then(t => console.log(t))

in the log you can see the json response. try copy & paste the logs to json validator site(like devutils.org)

you can get hint from the site or you should copy & paste the response here for more help

Related