title: Javascript:handle Unexpected JSON error in express js
body: <p>I am trying to handle Unexpetced JSON in my express js application via try and catch, so what I am trying to do is</p>
  
  <pre><code>try{
    let body = JSON.parse(req.body);
  }catch(e){
     res.json({
      error:e
    })
  }
  </code></pre>
  
  <p>But the <code>Unexpected JSON</code> error not thrown in the <code>catch block</code>.</p>
  
  <p>Content-type is <code>application/json</code></p>
  
  <p>Here is the JSON request</p>
  
  <pre><code>{
      "userId":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InNoYW1vbjVAYWNjdWJpdHMuY29tIiwiaWQiOjExNCwiaWF0IjoxNTMxOTgyNDQ0LCJleHAiOjE1MzI1ODcyNDR9.dv1zEnLsmKXbSE4wKbSOdYX3p7v5N5nh9kbz6PA_4TE",
      "readValue":falseuyuyuyu
  }
  </code></pre>
  
  <p><code>readValue</code> is malformed </p>