title: How to decode access token and get username and email in java?
body: <p>How can I get the name and email from a token .</p>
  <p>Structure of the token using jwt.io
  <a href="http://prntscr.com/yzyf2b" rel="nofollow noreferrer">http://prntscr.com/yzyf2b</a></p>
  <p>Any help is appreciated.</p>
  <p>Update full solution with the help of below posts so credits to them .</p>
  <pre><code>            String jwtToken = token;
              System.out.println(&quot;------------ Decode JWT ------------&quot;);
              String[] split_string = jwtToken.split(&quot;\\.&quot;);
              String base64EncodedHeader = split_string[0];
              String base64EncodedBody = split_string[1];
              String base64EncodedSignature = split_string[2];
  
              System.out.println(&quot;~~~~~~~~~ JWT Header ~~~~~~~&quot;);
              Base64 base64Url = new Base64(true);
              String header = new String(base64Url.decode(base64EncodedHeader));
              System.out.println(&quot;JWT Header : &quot; + header);
  
              System.out.println(&quot;~~~~~~~~~ JWT Body ~~~~~~~&quot;);
              String body = new String(base64Url.decode(base64EncodedBody));
              System.out.println(&quot;JWT Body : &quot; + body);
  
              JSONObject jsonObject = new JSONObject(body);
              System.out.println(jsonObject.get(&quot;email&quot;));
              System.out.println(jsonObject.get(&quot;name&quot;));
          
  </code></pre>