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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
JSON Parsing, Validation, Transformation
00:00
5 left

JSON Parsing, Validation, Transformation

HardPython

Problem

DataBank Holdings receives monitoring events from a legacy system with inconsistent field formats. Write parse_monitoring_payload(payload) to validate each event, transform valid events into a canonical representation, and report invalid or duplicate events without stopping the batch.

The input is a dictionary decoded from JSON. It contains an events array. Each event must include string fields id, host, metric, unit, severity, and timestamp, plus a numeric value. Severity values are INFO, WARN, or CRIT. Timestamps must be UTC ISO 8601 strings ending in Z.

Return a dictionary with accepted and errors arrays. Preserve input order. Each accepted event must contain the stripped host, a lowercase underscore-separated metric name, a floating-point value, a lowercase unit, a normalized severity of info, warning, or critical, a Unix timestamp in seconds, and normalized labels. An event is invalid if a required field is missing, a value cannot be converted to a finite number, a timestamp is invalid, a label is not a string pair, or its normalized ID was already accepted.

Each error contains the event's zero-based index, its id when available, and a short reason.

Constraints

  • 1 <= len(payload["events"]) <= 10^4
  • Each event is a JSON object
  • IDs, hosts, metrics, and units contain at most 200 characters
  • Labels contain at most 20 string key-value pairs
  • Timestamps are UTC ISO 8601 strings ending in Z

Function Signature

def parse_monitoring_payload(payload):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.