Evaluate pretokenized paths over a JSON tree, including implicit array wildcards and explicit indices. Explain token consumption, typed representations, missing-path behavior, and tests built directly from syntax-tree nodes.
Evaluate Paths through a JSON Tree with Implicit Array Wildcards
Company: MongoDB
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
A parsed JSON syntax tree is already available. Given a path as a vector of strings, return the matching values. Object steps look up a field name. Array steps use an index when supplied; when no index is supplied, treat the array as an implicit wildcard and apply the remaining path to all its elements. Object member iteration order is not important.
### Constraints and Clarifications
No parser is required. For a precise practice interface, represent JSON as tagged null, Boolean, number, string, array, or object nodes. On an object, a token is a literal key. On an array, a canonical nonnegative decimal token is an index; an explicit * expands all children and consumes that token; any other token triggers implicit expansion without consuming it. Missing keys, out-of-range indices, or a scalar with remaining path produce no matches. Empty remaining path returns the current value, including an array or object, as one match. These syntax and boundary choices are explicit normalization because the report does not specify them. Preserve array order in the returned match list; there is no wildcard over object keys. No size bounds are given.
### Example
For {"users":[{"name":"A"},{"name":"B"}]}, path ["users","name"] returns ["A","B"] because the array is traversed implicitly. Path ["users","1","name"] returns ["B"]. Path ["users"] returns one match containing the complete users array under the terminal-value convention.
### What a Strong Answer Covers
Define a safe tagged representation, explain path-token consumption during explicit and implicit traversal, and return every matching value. Discuss tagged structures, unions or variants, and a virtual-class alternative. Describe manually constructed tests without requiring JSON parsing or relying on automatically generated deep equality.
### Follow-up Questions
- What happens with nested arrays before the next object key?
- How should a numeric-looking object key be interpreted?
- Why does implicit array traversal keep the same path position?
Overview: Evaluate pretokenized paths over a JSON tree, including implicit array wildcards and explicit indices. Explain token consumption, typed representations, missing-path behavior, and tests built directly from syntax-tree nodes.
Evaluate Paths through a JSON Tree with Implicit Array Wildcards
MongoDB
Oct 16, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0
A parsed JSON syntax tree is already available. Given a path as a vector of strings, return the matching values. Object steps look up a field name. Array steps use an index when supplied; when no index is supplied, treat the array as an implicit wildcard and apply the remaining path to all its elements. Object member iteration order is not important.
Constraints and Clarifications
No parser is required. For a precise practice interface, represent JSON as tagged null, Boolean, number, string, array, or object nodes. On an object, a token is a literal key. On an array, a canonical nonnegative decimal token is an index; an explicit * expands all children and consumes that token; any other token triggers implicit expansion without consuming it. Missing keys, out-of-range indices, or a scalar with remaining path produce no matches. Empty remaining path returns the current value, including an array or object, as one match. These syntax and boundary choices are explicit normalization because the report does not specify them. Preserve array order in the returned match list; there is no wildcard over object keys. No size bounds are given.
Example
For {"users":[{"name":"A"},{"name":"B"}]}, path ["users","name"] returns ["A","B"] because the array is traversed implicitly. Path ["users","1","name"] returns ["B"]. Path ["users"] returns one match containing the complete users array under the terminal-value convention.
What a Strong Answer Covers Guidance
Define a safe tagged representation, explain path-token consumption during explicit and implicit traversal, and return every matching value. Discuss tagged structures, unions or variants, and a virtual-class alternative. Describe manually constructed tests without requiring JSON parsing or relying on automatically generated deep equality.
Follow-up Questions Guidance
What happens with nested arrays before the next object key?
How should a numeric-looking object key be interpreted?
Why does implicit array traversal keep the same path position?