Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Manipulating Complex JSON
00:00
5 left

Manipulating Complex JSON

HardPython

Problem

Synechron frontend configuration tools receive deeply nested JSON payloads that must be edited without mutating the original input. Implement ordered JSON Pointer mutations for replacing existing values and deleting object properties or array elements.

Formal Specification

Write apply_operations(document, operations), where document is a JSON-compatible Python value containing dictionaries, lists, strings, numbers, booleans, or None. Each operation is a dictionary with:

  1. op: either "set" or "delete".
  2. path: a non-empty JSON Pointer string beginning with /. Object keys are separated by /, and ~1 represents / while ~0 represents ~.
  3. value: required only for "set".

Every path is valid for the document state at the time its operation runs. A set replaces an existing object value or array element. A delete removes an object property or removes an array element, shifting later elements left. Operations must be applied in order. Return a deep-copied document and leave document unchanged.

Constraints

  • 1 <= len(operations) <= 10^4
  • The document contains at most 10^5 total values
  • Paths begin with / and are valid JSON Pointer paths
  • Every operation targets an existing value
  • Operation values contain only JSON-compatible data

Function Signature

def apply_operations(document, operations):
Interviewer

Your question is Manipulating Complex JSON. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.