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
2 Answers
Reset to default 4Unexpected 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