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

213
Vistas
Node.js SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at IncomingMessage.<anonymous>

I'm trying to parse this data from Marvel API by using JSON.parse(); but I am not able to. I am using Node.js.

Here is the code which I am using to get data from the api:

app.post("/", function(req, res) {
  const nameStartsWith = req.body.superhero;
  const ts = "timestamp";
  const apikey = "myPublicKey";
  const hash = "md5 digest";
  const url = "http://gateway.marvel.com/v1/public/characters?ts=" + ts + 
              "&apikey=" + apikey + "&hash=" + hash + "&nameStartsWith=" 
              + nameStartsWith;

  http.get(url, function(response) {

    response.on("data", function(data) {
      // getting error here
      console.log(JSON.parse(data));
    });
  });
});

Below is the incomplete JSON data:

    {"code":200,"status":"Ok","copyright":"© 2022 MARVEL","attributionText":"Data provided by Marvel. © 2022 MARVEL","attributionHTML":"<a href=\"http://marvel.com\">Data provided by Marvel. © 2022 MARVEL</a>","etag":"08aea880d9e638f37cf6011d63a936fbe3f82f22","data":{"offset":0,"limit":20,"total":5,"count":5,"results":[{"id":1009718,"name":"Wolverine","description":"Born with super-human senses and the power to heal from almost any wound, Wolverine was captured by a secret Canadian organization and given an unbreakable skeleton and claws. Treated like an animal, it took years for him to control himself. Now, he's a premiere member of both the X-Men and the Avengers.","modified":"2016-05-02T12:21:44-0400","thumbnail":{"path":"http://i.annihil.us/u/prod/marvel/i/mg/2/60/537bcaef0f6cf","extension":"jpg"},"resourceURI":"http://gateway.marvel.com/v1/public/characters/1009718","comics":{"available":2549,"collectionURI":"http://gateway.marvel.com/v1/public/characters/1009718/comics","items":[{"resourceURI":"http://gateway.marvel.com/v1/public/comics/41113","name":"5 Ronin (Hardcover)"},{"resourceURI":"http://gateway.marvel.com/v1/public/comics/38756","name":"5 Ronin (2010) #1"

It is showing this error in my hyper terminal:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (C:\Users\mishr\OneDrive\Desktop\MarvelComics-Project\app.js:79:24)
about 4 years ago · Santiago Gelvez
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