最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is Unexpected token a in JSON at position 0? - Stack Overflow

programmeradmin1浏览0评论

I am getting an error that says SyntaxError: Unexpected token a in JSON at position 0 and I cannot find any information on what "a" means. I know that the JSON is not undefined. Can anyone help me understand what is causing this error?

Here is the code block that is causing the error:

let db_creds = await getDBCredentials();
console.log(db_creds)
const pool = new Pool(JSON.parse(db_creds['SecretString']));
console.log(pool)

I am getting an error that says SyntaxError: Unexpected token a in JSON at position 0 and I cannot find any information on what "a" means. I know that the JSON is not undefined. Can anyone help me understand what is causing this error?

Here is the code block that is causing the error:

let db_creds = await getDBCredentials();
console.log(db_creds)
const pool = new Pool(JSON.parse(db_creds['SecretString']));
console.log(pool)
Share Improve this question asked Nov 15, 2021 at 19:28 wezrinewezrine 831 gold badge2 silver badges11 bronze badges 3
  • What do you see on the console from the console.log at second line? – atiqorin Commented Nov 15, 2021 at 19:31
  • @atiqorin ``` { SecretString: 'arn:aws:SECRETSTRINGINEED' } ``` – wezrine Commented Nov 15, 2021 at 19:33
  • 7 @wezrine You try to parse the string arn:aws:SECRETSTRINGINEED as JSON. It isn't valid JSON. The "token" (character) at position 0 (the very first), isn't a character that valid JSON can start with. Which is the "a". – Ivar Commented Nov 15, 2021 at 19:35
Add a ment  | 

2 Answers 2

Reset to default 4

Unexpected Token < in JSON at Position 0. From time to time when working with JSON data, you might stumble into errors regarding JSON formatting. For instance, if you try to parse a malformed JSON with the JSON. ... json() method on the fetch object, it can result in a JavaScript exception being thrown.

What Is JSON and How to Handle an “Unexpected Token” Error

Well for me it was because the port was already in use and it must be sending HTML, you can try killing the port by running the below mand in cmd(admin mode)

taskkill /F /IM node.exe

发布评论

评论列表(0)

  1. 暂无评论