Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda