Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse API JSON Response

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

Your question is Parse API JSON Response. 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

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