Implement Recursive React JSON Viewer with Collapse

Quick Overview

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.

Implement Recursive React JSON Viewer with Collapse

Company: Notion

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

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: ( 1) Support arbitrarily deep nesting by recursively rendering child components. ( 2) Parse the input string safely; handle invalid JSON gracefully. ( 3) Maintain per-node expand/collapse state. ( 4) 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. ( 5) Briefly explain your component structure, state shape, and complexity considerations.

Quick Answer: 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.

|Home/Software Engineering Fundamentals/Notion
Notion logo
Notion
Jul 17, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
44
0

Implement Recursive React JSON Viewer with Collapse

React JSON Tree Viewer (Read-Only, Recursive)

Design and implement a React component that accepts a JSON string and renders a pretty-printed, read-only tree view. Each nested object or array must be collapsible/expandable via a toggle (e.g., a caret).

Requirements

  1. Support arbitrarily deep nesting by recursively rendering child components.
  2. Parse the input string safely; handle invalid JSON gracefully (show a helpful error without crashing).
  3. Maintain per-node expand/collapse state.
  4. Demonstrate the behavior using the input below. The "school" node should be collapsible/expandable:
    • Provided (non-strict) input: {name: "bob", age: 5, nicknames: ["bobby", "bobman"], school: {name: "bob university", year: 2015}}
    • Valid JSON to use in the demo: {"name":"bob","age":5,"nicknames":["bobby","bobman"],"school":{"name":"bob university","year":2015}}
  5. Briefly explain the component structure, state shape, and complexity considerations.

Assumptions

  • Use modern React (functional components + hooks, React 17/18+).
  • No external libraries required; plain CSS/inline styles are fine.
  • The component is read-only (no editing).

Clarifying Questions to Ask Guidance

  • Clarify the goal, inputs, constraints, stakeholders, and success criteria.
  • State assumptions before using them.
  • Keep the answer grounded in the prompt rather than adding outside facts.

What a Strong Answer Covers Guidance

  • A structured framing of the problem and constraints.
  • A concrete approach with trade-offs and edge cases.
  • A way to validate the answer and communicate the recommendation.

Follow-up Questions Guidance

  • What assumption is most important to validate first?
  • What could make the answer fail in practice?
  • How would you explain the result to a non-technical stakeholder?
Loading comments...