evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a resilient data processing service that streams JSON from an API and continues processing even when individual callbacks fail.
Your service receives a large JSON array of user records from a streaming API. Some records may trigger errors during processing (invalid format, missing required fields, etc.), but the service must continue processing all remaining records and collect both successful results and error information.
Create a function processUserStream(url, onComplete) that:
onComplete(results, errors) when done, where:
results is an array of successfully processed user recordserrors is an array of objects containing error information (e.g., {index, message})For each user record in the stream at path users.*, apply this transformation:
name field to uppercase (call .toUpperCase() on it)processed: true flagid, name, and email fieldsNote: Some records may have missing or invalid name fields, which will cause .toUpperCase() to throw an error. Your solution must handle this gracefully.
.toUpperCase() on undefined) must NOT stop the stream{
"users": [
{"id": 1, "name": "alice", "email": "alice@example.com"},
{"id": 2, "email": "bob@example.com"},
{"id": 3, "name": "charlie", "email": "charlie@example.com"}
]
}For the above input (where the second record has no name field), the function should produce:
results = [
{id: 1, name: "ALICE", email: "alice@example.com", processed: true},
{id: 3, name: "CHARLIE", email: "charlie@example.com", processed: true}
]
errors = [
{index: 1, message: "Cannot read property 'toUpperCase' of undefined"} // or similar
]/**
* Processes a stream of user records from a JSON API with error resilience.
*
* @param {string} url - The URL to fetch JSON data from
* @param {Function} onComplete - Callback invoked when processing completes: onComplete(results, errors)
* @returns {void}
*/
function processUserStream(url, onComplete) {
// IMPLEMENTATION HERE
}
module.exports = { processUserStream };Provides streaming JSON parsing support.