2023. 8. 9. 00:26, 크래프톤 정글/웹
{
"name": "hyeok123",
"email": "hyeok123@naver.com",
"password": "1234567",
}
처음에 이런식으로 작성해서 요청을 보낼때,
처음에 이런식으로 작성해서 요청을 보낼때,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token } in JSON at position 92<br> at JSON.parse (<anonymous>)<br> at parse (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\body-parser\lib\types\json.js:92:19)<br> at C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\body-parser\lib\read.js:128:18<br> at AsyncResource.runInAsyncScope (node:async_hooks:203:9)<br> at invokeCallback (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:238:16)<br> at done (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:227:7)<br> at IncomingMessage.onEnd (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:287:7)<br> at IncomingMessage.emit (node:events:513:28)<br> at endReadableNT (node:internal/streams/readable:1359:12)<br> at process.processTicksAndRejections (node:internal/process/task_queues:82:21)</pre>
</body>
</html>
아래와 같은 오류 메세지를 받을 수 있었다.
이에 대해서 gpt에 검색해본 결과,
아래와 같은 오류 메세지를 받을 수 있었다.
이에 대해서 gpt에 검색해본 결과,
이와 같은 답을 얻을 수 있었고, JSON 부분에 뭔가 작성이 잘못 되었구나 싶어서 포스트맨을 보니까,
이와 같이 맨 마지막에 ( , ) 일 찍어좋은 상태였고, 빨간 밑줄이 그어져 있었다.
trailing comma에 대한 내용을 볼 수 있었고, 이에 대해서 검색을 해보니,
이와 같은 답을 얻을 수 있어서, 그렇다면 JSON 형태로 작성한것은 trailing comma가 가능한지 검색해보았다.
결국 짧게 말하면, 자바스크립는 ES5 이후부터는 trailing comma가 가능하고, JSON은 trailing comma가 불가능하다는걸 알 수 있었고, 내가 자바스크립트에서 객체 표현할때처럼 맨 마지막에 ( , ) 를 찍었기 때문에 JSON에서는 불가능한 trailing comma를 사용해서 파싱이 되지 않았던 것이다.
JSON을 작성할때는 trailing comma를 주의하도록 하자.
'크래프톤 정글 > 웹' 카테고리의 다른 글
spring boot 에서 카카오, 네이버 로그인 구현에 관련된 블로그 글. 혹시몰라 기록해둠. (0) | 2023.08.06 |
---|---|
OAuth 2.0 기반 카카오 로그인에서 토큰 저장 위치에 관하여. (0) | 2023.08.05 |
카카오 로그인(OAuth 2.0 REST API) + JWT 토큰 방식 로그인 기능구현 참고할만한 블로그 글들 (0) | 2023.08.04 |
Cookies에서 확인해볼 수 있는 connect.sid에 대하여. (0) | 2023.08.04 |
토큰 유형에 대한 구글에서 제공해주는 문서 위치 (0) | 2023.08.03 |
Comments, Trackbacks