javascript

Decode JWT Token

Get JWT token payload using JavaScript Buffer

Tarun Sharma
Tarun SharmaAugust 29, 2022 ยท 1 min read ยท Last Updated:

javascript

function decodeJwt(token) {
  var base64Payload = token.split(".")[1];
  var payloadBuffer = Buffer.from(base64Payload, "base64");
  return JSON.parse(payloadBuffer.toString());
}

Usage

var payload = decodeJwt(
  "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
);
console.log(payload);

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub


Tarun Sharma

Written byTarun Sharma
Tarun Sharma is a software engineer by day and a full-stack developer by night. He's coding for almost a decade now. He codes ๐Ÿง‘โ€๐Ÿ’ป, write โœ๏ธ, learn ๐Ÿ“– and advocate ๐Ÿ‘.
Connect

Is this page helpful?

Related ArticlesView All

Related VideosView All

Stack Overflow Clone - APIs Integration Redux Toolkit [Closure] - App Demo #05

Become Ninja Developer - API security Best Practices with Node JS Packages #15

Nest JS Microservices using HTTP Gateway and Redis Services (DEMO) #nestjs #microservices #16