Problem, as an interviewer would state it:
"Implement a simplified JSONPath evaluator supporting dot-notation paths and a [*] wildcard — $.users[*].name should return every user's name from a real array of user objects."
Examples:
jsonPathLite(data, "$.users[*].name"); // ["Ada", "Grace", "Alan"]
Clarifying questions expected:
- Does the function always return an ARRAY of matches, even when the path resolves to conceptually one value?
- What should a genuinely nonexistent path return — an empty array, or throw?
- Should this support multiple
[*]wildcards chained together (e.g., an array of arrays)?
Code / implementation expected: Yes — real, direct proof against a real, nested users array, correctly extracting every name and every age, and correctly returning empty for a nonexistent path.