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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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....