Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wahidsherief's avatar

getting Unrecognized token '<" when json.stringify data send from react-native to laravel controller

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";
}
0 likes
1 reply
ejdelmonico's avatar

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.

Please or to participate in this conversation.