PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Decode a JWT string without libraries

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of JWT structure, Base64URL encoding, string manipulation, and JSON parsing as applied to decoding token components. It is commonly asked to assess practical implementation abilities and edge-case/error handling in the Coding & Algorithms domain, emphasizing practical application over purely conceptual reasoning.

  • hard
  • Microsoft
  • Coding & Algorithms
  • Software Engineer

Decode a JWT string without libraries

Company: Microsoft

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Implement a function that **decodes** (but does not necessarily verify) a JWT token. A JWT is a string of the form: ``` <base64url(header)>.<base64url(payload)>.<base64url(signature)> ``` Where `header` and `payload` are UTF-8 JSON. ### Task Write a function (language: **C#**) that: 1. Splits the token into 3 parts. 2. Performs **Base64URL** decoding (note: `-` and `_` instead of `+` and `/`, and padding `=` may be missing). 3. Decodes the header and payload into JSON strings (or into dictionaries/objects if you prefer). 4. Returns the decoded header and payload. ### Notes / Edge cases - Handle missing padding correctly. - If the token is malformed (wrong number of segments, invalid base64, non-JSON payload), return an error / throw. - You do **not** need to validate the signature unless explicitly stated.

Quick Answer: This question evaluates understanding of JWT structure, Base64URL encoding, string manipulation, and JSON parsing as applied to decoding token components. It is commonly asked to assess practical implementation abilities and edge-case/error handling in the Coding & Algorithms domain, emphasizing practical application over purely conceptual reasoning.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Feb 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
1
0
Loading...

Implement a function that decodes (but does not necessarily verify) a JWT token.

A JWT is a string of the form:

<base64url(header)>.<base64url(payload)>.<base64url(signature)>

Where header and payload are UTF-8 JSON.

Task

Write a function (language: C#) that:

  1. Splits the token into 3 parts.
  2. Performs Base64URL decoding (note: - and _ instead of + and / , and padding = may be missing).
  3. Decodes the header and payload into JSON strings (or into dictionaries/objects if you prefer).
  4. Returns the decoded header and payload.

Notes / Edge cases

  • Handle missing padding correctly.
  • If the token is malformed (wrong number of segments, invalid base64, non-JSON payload), return an error / throw.
  • You do not need to validate the signature unless explicitly stated.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Software Engineer•Microsoft Software Engineer•Microsoft Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.