Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

818
Vistas
I am getting such Kind Of Problem : Uncaught (in promise) SyntaxError: Unexpected end of JSON input

I am using react js and using mongo db. i am trying to get data by fetch. but i get this type of error : Uncaught (in promise) SyntaxError: Unexpected end of JSON input

const [product, setProduct] = useState({});
useEffect(() => {
  const url = `http://localhost:5000/product/${id}`;
  fetch(url)
    .then((res) => res.json())
    .then((data) => setProduct(data));
}, [id]);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Your code in useEffect is correct the reason you may be getting this error is because of

  1. There is no JSON data from the backend
  2. Maybe the JSON you received is not proper JSON

you can confirm this by replacing res.json() with res.text() and then console.log it

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should include a .catch() call in your chain of method calls off the fetch, so that you can handle errors or malformed input from your API. The error is saying it's "uncaught" because there is no catch clause.

i.e.

  fetch(url)
    .then((res) => res.json())
    .then((data) => setProduct(data))
    .catch((error) => console.error("Something went wrong: ", error))
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda