(
file: File,
options: {
onChunkParsed?: (chunk: any[], isFirstChunk: boolean) => void;
onProgress?: (progress: number, stats: StreamingJSONParseStats) => void;
sampleLimit?: number;
} = {}
)
| 306 | * Parse a JSON file with progress tracking |
| 307 | */ |
| 308 | const parseJson = async ( |
| 309 | file: File, |
| 310 | options: { |
| 311 | onChunkParsed?: (chunk: any[], isFirstChunk: boolean) => void; |
| 312 | onProgress?: (progress: number, stats: StreamingJSONParseStats) => void; |
| 313 | sampleLimit?: number; |
| 314 | } = {} |
| 315 | ): Promise<DataParseResult> => { |
| 316 | try { |
| 317 | setIsLoading(true); |
| 318 | setError(null); |
| 319 | setProgress(0); |
| 320 | |
| 321 | // Stream the file |
| 322 | const fileStream = file.stream(); |
| 323 | |
| 324 | // Parse the stream |
| 325 | const result = await parseJSONStream(fileStream, { |
| 326 | ...options, |
| 327 | estimatedTotalBytes: file.size, |
| 328 | onComplete: (result) => { |
| 329 | result.fileName = file.name; |
| 330 | } |
| 331 | }); |
| 332 | |
| 333 | return result; |
| 334 | } catch (err) { |
| 335 | const errorMessage = err instanceof Error ? err.message : 'Unknown error parsing JSON'; |
| 336 | setError(errorMessage); |
| 337 | setIsLoading(false); |
| 338 | throw err; |
| 339 | } |
| 340 | }; |
| 341 | |
| 342 | /** |
| 343 | * Parse a JSON text string directly (for small data) |
nothing calls this directly
no test coverage detected