1000ship / incomplete-json-parser

🎢 A streaming JSON parser that can handle incomplete or chunked JSON data.
14 stars 2 forks source link

🐛 Trailing whitespace causes parser to fail #1

Open ka-fuachie opened 4 days ago

ka-fuachie commented 4 days ago

Description

The current implementation of the JSON parser fails when parsing valid JSON that contains trailing whitespace after the closing bracket or brace. This behavior is inconsistent with the JSON.parse, which allows for insignificant whitespace outside of the outermost brackets.

Steps to reproduce

Attempt to parse JSON string

console.log(IncompleteJsonParser.parse('    {"key": "value"}    '))

Current behaviour

The parser throws Error: Parser is already finished

Expected Behavior

The parser should successfully parse the JSON string, ignoring the trailing whitespace.

ka-fuachie commented 3 days ago

I have a PR with a suggested fix #2