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
Efficient JSON Transformations
00:00
5 left

Efficient JSON Transformations

HardPython

Problem

Palo Alto Networks frontend surfaces such as Cortex XSIAM may receive deeply nested JSON configuration and alert objects. Implement a function that removes every object field whose dot-separated path appears in a blocked-path list, including the field's entire subtree.

Formal Specification

Given a JSON-compatible value data and an array blocked_paths, return a new JSON-compatible value with all matching fields removed. A path such as user.credentials.token refers only to object keys, and array elements do not add path components. Apply the same path rules independently to every object inside an array. Preserve the order of object keys and array elements. Do not mutate data.

Use a trie for blocked paths so shared prefixes are represented once and a blocked subtree can be skipped without traversing its descendants. Object keys used in paths do not contain periods. The root itself is never blocked.

Constraints

  • data contains only objects, arrays, strings, numbers, booleans, and null
  • 1 <= number of blocked paths <= 10^4
  • Each path contains 1 to 100 keys
  • The total number of path components is at most 10^5
  • The JSON tree contains at most 10^5 values
  • Object keys used in paths do not contain periods
  • The root itself is never blocked

Function Signature

def filter_json(data, blocked_paths):
Interviewer

Your question is Efficient JSON Transformations. 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.