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

274
Vistas
How to Fix "unexpected end of JSON" error?

I'm working on blockchain based document verification system. The system works perfectly when there is a document issued by the user. The problem is when there is no issued document by the user(for example, when the user is new), the error is with the following code,

<% console.log('fit', JSON.parse(documents, null, '\t')) %>

When a document is issued by the user, it returns the following JSON data:

fit

[
  {
    Key: 'DOCUMENT0',
    Record: {
      name: 'bachelor of science degree',
      url: 'https://bitcoin.org/ggg.pdf',
      issuedBy: 'sol123',
      dateOfIssuance: '12:18 PM, 25 September, 2021',
      hashedDoc: 'dac729a8acf4b8a88f73f5bd84206c34e01e0992efa251b772f68696e2c2539c9ed0090e73ef6b87dc24e3177c6fd5341c3e9e24ef14267ce07ab9428aeed897',
      docType: 'Whitepaper'
    }
  }
]

The problem is when a user creates account(signup) and login to the system for the first time or when there is no document issued by the user,it returns the following error:

SyntaxError: /home/bishoftu/fabcar/javascript/views/pages/dashboard.ejs:13

11| 
12|     <div class="list-group" id="list-tab" role="tablist" style="margin-top: 10px;">

13| <% console.log('fit', JSON.parse(documents, null, '\t')) %> 14|

Unexpected end of JSON input at JSON.parse ()

What i want is to display the message "NO DOCUMENT ISSUED", when there is no document issued by the user.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Put the JSON.parse() in a try/catch statement, and log a custom error if it fails:

try
{
    let json = JSON.parse(documents, null, '\t');
    console.log(json);
}
catch(error)
{
    console.info("NO DOCUMENT ISSUED");
}
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