Scriptbar Snippets 🚀
Handy and easy to understand snippets to keep in your browser


Decode JWT token

Expose a global method decodeJwt(token) to decode a JWT token.

See for more detail



Output: '{"sub":"1234567890","name":"John Doe","iat":1516239022}'

/* * Decode jwt token * See */ (function (root) { root.decodeJwt = (token) => decodeURIComponent( atob(token.split(".")[1].replace("-", "+").replace("_", "/")) .split("") .map((c) => `%${("00" + c.charCodeAt(0).toString(16)).slice(-2)}`) .join("") ); })(this); console.log("%c Init method to decode jwt token. Below is example", 'background: #222; color: #bada55'); decodeJwt(` eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0I joxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c `);
Built with ❤️ by @domnguyen and everyone on the internet 🚀