Fetch and parse JSON from REST API
MotiveSoftware Engineer · OnsiteLast updated
A Motive Software Engineer onsite coding exercise: build a small, resilient script from scratch that performs an authenticated HTTP GET against a paginated REST API, parses the JSON, extracts and transforms records, and produces both serialized CSV/JSON output and per-category top-k aggregates. It evaluates HTTP/REST integration, rate-limit and retry handling with backoff, timeouts, malformed-record handling, unit testing, logging, and complexity analysis.
Question
Set up a minimal coding environment from scratch and write runnable code that fetches and processes data from a REST API. You are given an endpoint that returns a JSON payload (for example, fleet/courier tracking records with fields such as order_id, courier_id, latitude, longitude, and timestamp). Perform an HTTP GET against the endpoint, parse the response, extract the specified fields, and produce the required output. Walk the interviewer through your approach as you go.
Your solution should address all of the following:
- HTTP integration. Perform the HTTP GET and parse the JSON response. Handle authentication (e.g., bearer token / API key).
- Robustness. Handle pagination, rate limiting (backoff/retry with exponential backoff), request timeouts, and malformed or partial records without crashing the run.
- Field extraction & transformation. Extract the specified fields and transform the records into the required target schema.
- Output #1 — serialized records. Output the transformed records as CSV and/or JSON.
- Output #2 — aggregation. Compute aggregates per category and return the top-k items.
- Quality. Include basic unit tests, plus error handling and logging.
- Analysis. Explain your approach, the edge cases you considered, and the time/space complexity of your solution.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.