Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!