Chunked JSON Parse Problem
NodeJS
Hard
3 views
Problem Description
Explain why JSON.parse on stream chunks fails, and fix by buffering.
Output Format
Print parsed name.
Constraints
Simulate chunks split in middle.
Official Solution
const chunks = ['{\"name\":\"mee', 'tcode\"}'];
let buf = '';
for (const c of chunks) buf += c;
const obj = JSON.parse(buf);
console.log(obj.name);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!