Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse API JSON Response

EasyPython00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the Python screen.

The question is on your right: Parse API JSON Response. Read through the requirements first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Implement a function parse_api_response(status_code, payload) that processes an API response for a mobile client. The input is an integer HTTP-like status_code and a JSON string payload. If status_code is not 200, return an empty list. Otherwise, parse the JSON and return a list of model dictionaries from the rides array. Each returned model must contain only id, driver_name, and eta_minutes. Skip any ride object missing one of those fields or having invalid types.

Constraints

  • 100 <= status_code <= 599
  • 0 <= len(payload) <= 10^5
  • The top-level JSON may be invalid, may omit rides, or may contain malformed ride objects

Function Signature

def parse_api_response(status_code, payload):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output