Level 53
Check to make sure your request body is not html. That error can occur if the response has html and you run JSON.stringify() on it.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to post data from react native app by json.stringify to Laravel controller. But getting "JSON Parse error: Unrecognized token '<'". I need help how to resolve it. My code are given below:
react-native end:
fetch(API_URL+'/signup', {
method: 'post',
header:{
'Accept': 'application/json',
'Content-type': 'application/json'
},
body:JSON.stringify({
name: userName,
email: userEmail,
password: userPassword
})
})
.then((response) => response.json())
.then((response) =>{
alert(response);
})
.catch((error)=>{
console.error(error);
});
Laravel:
public function registerUser()
{
$this->validate(request(), [
'email' => 'required|email',
'name' => 'required',
'password' => 'required|min:4|confirmed'
]);
$user = User::create(request(['email', 'name', 'password']));
return "success";
}
Please or to participate in this conversation.