evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a Node.js application that processes streaming JSON data from an HTTP endpoint and extracts specific information based on patterns.
Create a module that:
The streaming endpoint returns JSON in this structure:
{
"users": [
{
"id": 1,
"name": "Alice",
"email": "alice@example.com",
"active": true
},
{
"id": 2,
"name": "Bob",
"email": "bob@example.com",
"active": false
}
]
}Your implementation should:
active is true/**
* Fetches and processes streaming JSON data from the given URL
* @param {string} url - The URL to fetch JSON data from
* @param {function} callback - Called with (error, emails) when complete
*/
function processUserStream(url, callback) {
// Your implementation here
}Provides streaming JSON parsing capabilities for processing data as it arrives.
Setup:
const http = require('http');
// Mock server that returns user data
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
users: [
{ id: 1, name: "Alice", email: "alice@example.com", active: true },
{ id: 2, name: "Bob", email: "bob@example.com", active: false },
{ id: 3, name: "Charlie", email: "charlie@example.com", active: true }
]
}));
});
server.listen(3000);Input:
processUserStream('http://localhost:3000', (err, emails) => {
console.log(emails);
});Expected Output:
['alice@example.com', 'charlie@example.com']Cleanup:
server.close();Setup:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
users: [
{ id: 1, name: "Bob", email: "bob@example.com", active: false },
{ id: 2, name: "Dave", email: "dave@example.com", active: false }
]
}));
});
server.listen(3001);Input:
processUserStream('http://localhost:3001', (err, emails) => {
console.log(emails);
});Expected Output:
[]Cleanup:
server.close();