HardPro challengePythonJavaScriptTypeScript

Incremental JSON Array Parser

Node.jsJSONStreams

Parse a stream of chunks (array of strings) that together form a JSON array.
Yield each top-level array element as a parsed object. Brackets/quotes may be
split across chunks.

solve(chunks) returns an array of parsed elements.

Sample tests

Test #1Empty array
Input: [["[]"]]
Output: []
Test #2Numbers single chunk
Input: [["[1,2,3]"]]
Output: [1,2,3]
Test #3Objects split
Input: [["[{\"a\":1}",",{\"b\":2}]"]]
Output: [{"a":1},{"b":2}]
Test #4Strings with chunked commas
Input: [["[","\"a\"",",","\"b\"","]"]]
Output: ["a","b"]
Test #5Nested arrays
Input: [["[[1,2],[3,4]]"]]
Output: [[1,2],[3,4]]