or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Real-time JSON Progress Monitor

Build a progress monitoring system that tracks and reports the parsing progress of a streaming JSON response. The system should provide real-time insights into how much data has been received and parsed at various checkpoints during the streaming process.

Requirements

Your implementation should:

  1. Accept a readable stream containing JSON data
  2. Monitor the parsing progress at regular intervals
  3. Track key metrics about the parsed data structure
  4. Provide snapshots of the partially parsed JSON tree
  5. Report when parsing is complete

Progress Tracking

The system should capture progress snapshots that include:

  • The current state of the JSON tree (even if incomplete)
  • A timestamp for when the snapshot was taken
  • A count of how many top-level properties have been parsed so far
  • Whether the parsing is still in progress or complete

Implementation

@generates

API

/**
 * Creates a progress monitor for streaming JSON parsing.
 *
 * @param {Stream} stream - A readable stream containing JSON data
 * @param {Function} progressCallback - Called periodically with progress info:
 *   {
 *     timestamp: number,        // Unix timestamp in milliseconds
 *     currentData: object|array, // Current state of parsed JSON tree
 *     topLevelCount: number,    // Number of top-level properties/items parsed
 *     isComplete: boolean       // Whether parsing is finished
 *   }
 * @param {number} intervalMs - Milliseconds between progress checks (default: 100)
 * @returns {Promise<object>} Resolves with the complete parsed JSON
 */
function monitorProgress(stream, progressCallback, intervalMs) {
  // IMPLEMENTATION HERE
}

module.exports = { monitorProgress };

Test Cases

  • Given a stream with JSON object {"a": 1}, progress callback receives at least one update with partial data @test
  • Given a stream with JSON array [1, 2, 3], progress callback receives updates showing increasing topLevelCount @test
  • Given a stream with large JSON object, final progress update has isComplete set to true @test
  • Given a JSON stream with 5 top-level properties, final topLevelCount equals 5 @test

Dependencies { .dependencies }

oboe { .dependency }

Provides streaming JSON parsing with progressive access to partial results.

@satisfied-by