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
JSON Manipulation Program
00:00
5 left

JSON Manipulation Program

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 Python 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 Python 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

Your question is JSON Manipulation Program. 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.