Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

JSON Manipulation Program

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is JSON Manipulation Program. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output