Parse a Nested Config String Into Flattened Dotted Keys

Last updated: November 29, 2026

Quick Overview

Service configs arrive as a JSON-like string containing objects, arrays, double-quoted strings, integers, true, false and null. Without using a JSON library, parse it and return a flat dict whose keys are dotted paths such as `surge.cities.0.name`.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Service configs arrive as a JSON-like string containing objects, arrays, double-quoted strings, integers, true, false and null. Without using a JSON library, parse it and return a flat dict whose keys are dotted paths such as `surge.cities.0.name`.

An Uber onsite question for infrastructure-leaning roles, inspired by flattening dynamic config into key-value pairs. Interviewers check parser structure, whitespace handling, and clean recursion over nested values.

What the Interviewer Expects
  • Writes a recursive descent parser with one function per value type
  • Skips whitespace consistently between tokens
  • Handles escaped quotes inside strings
  • Flattens with path prefixes, using indices for arrays
  • Raises errors with a position on malformed input
Key Topics to Cover
string parsing
recursive descent
tree flattening
JSON
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle keys that themselves contain dots?
  • Unflatten dotted keys back into a nested structure.
  • How would you stream-parse a 2 GB config without loading it all?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: string with a subset of JSON (no floats or unicode escapes needed).
  • Output: dict of dotted path to leaf value.
  • Empty objects or arrays produce no keys....
High-Level Design

Two steps. First parse into Python values with a small recursive descent parser: value() looks at the next non-space character and dispatches to obj(), arr(), string(), a literal, or a number....


Submit Your Answer
Markdown supported