CodeWithHarry / NextJs-Course

115 stars 51 forks source link

"Unexpected end of JSON input" when I am trying to parse the data. #2

Closed harkaran911 closed 2 years ago

harkaran911 commented 2 years ago

Hello harry sir. I have a problem regrading the course. I am currently on tutorial #18 where the data is being parsed from how-to-learn-flask.json. Here's the code:-

// Next.js API route support: https://nextjs.org/docs/api-routes/introduction import * as fs from 'fs';

export default function handler(req, res) { fs.readFile("blogdata/how-to-learn-flask.json", 'utf-8', (err, data) => { console.log('') res.status(200).json( JSON.parse(data) ) }) }

The error is:-

error - uncaughtException: SyntaxError: Unexpected end of JSON input.

Plus there is no change on the api page.

I very much like the course. Please tell me a solution to this.

Thanks.

harkaran911 commented 2 years ago

I am so dumb. I now realized that there was no json data in the file. I am sorry for trouble.