Implement Recursive React JSON Viewer with Collapse
NotionSoftware Engineer · Technical ScreenLast updated
Implement Recursive React JSON Viewer with Collapse evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Build a React component that accepts a JSON string and renders a pretty-printed, read-only tree view. For each nested object or array, display a toggle (e.g., a 🔽 caret) to collapse/expand that node. Requirements: (
- Support arbitrarily deep nesting by recursively rendering child components. (
- Parse the input string safely; handle invalid JSON gracefully. (
- Maintain per-node expand/collapse state. (
- Demonstrate the behavior using input: {name: "bob", age: 5, nicknames: ["bobby", "bobman"], school: {name: "bob university", year: 2015}} where the "school" node can be toggled. (
- Briefly explain your component structure, state shape, and complexity considerations.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.