서버로 body에 json 형태로 데이터를 보낼때 주의할 부분(postman 사용시에 발견한 사항)
{
    "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> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\body-parser\lib\types\json.js:92:19)<br> &nbsp; &nbsp;at C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\body-parser\lib\read.js:128:18<br> &nbsp; &nbsp;at AsyncResource.runInAsyncScope (node:async_hooks:203:9)<br> &nbsp; &nbsp;at invokeCallback (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:238:16)<br> &nbsp; &nbsp;at done (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:227:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\progr\Desktop\practice_for_react\boiler-plate\node_modules\raw-body\index.js:287:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (node:events:513:28)<br> &nbsp; &nbsp;at endReadableNT (node:internal/streams/readable:1359:12)<br> &nbsp; &nbsp;at process.processTicksAndRejections (node:internal/process/task_queues:82:21)</pre>
</body>

</html>

아래와 같은 오류 메세지를 받을 수 있었다.
이에 대해서 gpt에 검색해본 결과, 


이와 같은 답을 얻을 수 있었고, JSON 부분에 뭔가 작성이 잘못 되었구나 싶어서 포스트맨을 보니까, 


이와 같이 맨 마지막에 ( , ) 일 찍어좋은 상태였고, 빨간 밑줄이 그어져 있었다.

trailing comma에 대한 내용을 볼 수 있었고, 이에 대해서 검색을 해보니, 

 

이와 같은 답을 얻을 수 있어서, 그렇다면 JSON 형태로 작성한것은 trailing comma가 가능한지 검색해보았다. 

결국 짧게 말하면, 자바스크립는 ES5 이후부터는 trailing comma가 가능하고, JSON은 trailing comma가 불가능하다는걸 알 수 있었고, 내가 자바스크립트에서 객체 표현할때처럼 맨 마지막에 ( , ) 를 찍었기 때문에 JSON에서는 불가능한 trailing comma를 사용해서 파싱이 되지 않았던 것이다.

 JSON을 작성할때는 trailing comma를 주의하도록 하자. 

 

  Comments,     Trackbacks