React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

Add two headers Content-Type and Accept to be equal to application/json.

handleGetJson(){
  console.log("inside handleGetJson");
  fetch(`./fr.json`, {
      headers : { 
        'Content-Type': 'application/json',
        'Accept': 'application/json'
       }

    })
    .then((response) => response.json())
    .then((messages) => {console.log("messages");});
}

Leave a Comment