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
Flatten Nested Authorization Event JSON
00:00
5 left

Flatten Nested Authorization Event JSON

EasyPython

Problem

Visa Acceptance Platform authorization events arrive as nested JSON objects. Write a function that extracts selected fields and returns one flattened record per event, preserving None for optional fields that are absent.

Formal Specification

Implement extract_authorization_fields(events), where events is a list of dictionaries produced by parsing JSON. Return a list of dictionaries with these keys:

  • transaction_id from data.authorizationId
  • status from data.status
  • amount from data.amount.value
  • currency from data.amount.currency
  • merchant_category from data.merchant.categoryCode
  • card_last4 from data.paymentMethod.card.last4
  • created_at from data.createdAt

Every event contains data.authorizationId. All other fields are optional. Do not modify the input or include keys outside the specified output schema.

Example 1

Input: [{"data": {"authorizationId": "A100", "status": "APPROVED", "amount": {"value": 2599, "currency": "USD"}, "merchant": {"categoryCode": "5411"}, "paymentMethod": {"card": {"last4": "4242"}}, "createdAt": "2026-04-01T10:00:00Z"}}]

Output: [{"transaction_id": "A100", "status": "APPROVED", "amount": 2599, "currency": "USD", "merchant_category": "5411", "card_last4": "4242", "created_at": "2026-04-01T10:00:00Z"}]

The nested values are copied into a stable flat schema.

Example 2

Input: [{"data": {"authorizationId": "A101", "status": "DECLINED", "amount": {"value": 0, "currency": "EUR"}}}]

Output: [{"transaction_id": "A101", "status": "DECLINED", "amount": 0, "currency": "EUR", "merchant_category": null, "card_last4": null, "created_at": null}]

Missing optional paths become None, while valid zero values are retained.

Constraints

  • 1 <= len(events) <= 10^4
  • Each event is a valid JSON object represented as a dictionary
  • data.authorizationId exists in every event and is a non-empty string
  • Nested objects contain at most 10 levels
  • Field values are strings, integers, or null

Function Signature

def extract_authorization_fields(events):
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.