Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Render Dynamic Card From API

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

Your question is Render Dynamic Card From API. 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 that takes a JSON string returned by a mock API and converts it into a normalized card object with four required fields: heading, subheading, summary, and image. The input may contain extra fields, missing fields, or invalid JSON. Return the normalized object when valid, or null when the payload cannot produce a complete card.

Constraints

  • 1 <= len(payload) <= 10^5
  • Input is a JSON string representing a single object
  • Required source fields are title, subtitle, description, and imageUrl
  • Ignore extra keys in the payload
  • Return null for invalid JSON or missing/empty required fields

Function Signature

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