Skip to the solution
MediumLow-Level DesignAsked in 20247 min read

Implement a JSONPath-Lite Query Evaluator (Supports Wildcards Like $.users[*].name)

2.3k views

The problem

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:

Code
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.

  • js-coding
  • utility
  • algorithm

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

7 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, direct proof: the evaluator correctly extracts every name and every age from a real nested users array, and returns empty for a nonexistent path

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 67 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

Build a Dataloader-Style Batching Utility That Coalesces Individual Async Calls

Continue