javascript

Decode JWT Token

Get JWT token payload using JavaScript Buffer

Edson Frainlar
Edson FrainlarAugust 29, 2022 · 1 min read · Last Updated:

Method

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

Usage

1var payload = decodeJwt(
2 "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
3);
4console.log(payload);

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


Edson Frainlar

Written byEdson Frainlar
Mission-driven Full-stack Developer with a passion for developing KTern, Dev Collaboration, and teaching. Curious to explore Quantum Information and Computing.
Connect

Is this page helpful?

Related ArticlesView All

Related VideosView All

Easy NPM Package Updates with Yarn Upgrade Interactive

The Async Await Episode I Promised