You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you for raising this issue! The behavior of partial-json here is indeed not ideal. To be honest, there are a lot of similar problems, but people probably haven't mentioned them because they simply haven't encountered them.
The Python version of this library handles this case more thoroughly—it throws an error when it encounters invalid JSON. I think I can fix this issue in v0.2 of the JavaScript library.
However, I'm quite busy these days, so I'm wondering, is this something you need urgently? Maybe you could consider submitting a PR?
hello, @CNSeniorious000, thanks for the quick reply.
I'm ok with both suggested and current behavior, just need to know that provided JSON is malformed (not considering incomplete of course) - throwing an exception with whatever it parsed might work even though I have probably never seen such combination :).
I will be attending a hackathon starting tomorrow, but I will make sure to release a new version of this package that addresses these issues no later than July 30th.
Still present in 0.1.7 and on main (86fd4bc), Node.js 26. A minimal case for the "space between empty array brackets" report above, two documents, one per line. Paste into an empty folder:
In parseArr (src/index.ts L125-L144) there is no skipBlank() after index++, so for [ ] the loop calls parseAny(), which reaches parseNum and throws a malformed-JSON error. The catch returns the partial array because Allow.ARR is set, without consuming ], so the enclosing array or object ends at that ] and the rest of the input is ignored. Adding skipBlank() after index++ (as parseObj does after {) fixes this case; PR #13 contains that line, if the rest of #13 or #19 needs more time.
Activity
CNSeniorious000 commentedon Jul 18, 2025
Thank you for raising this issue! The behavior of
partial-jsonhere is indeed not ideal. To be honest, there are a lot of similar problems, but people probably haven't mentioned them because they simply haven't encountered them.The Python version of this library handles this case more thoroughly—it throws an error when it encounters invalid JSON. I think I can fix this issue in v0.2 of the JavaScript library.
However, I'm quite busy these days, so I'm wondering, is this something you need urgently? Maybe you could consider submitting a PR?
Minimal reproduction
Expected behavior
An error should be thrown instead of returning
[].@sKopheK Do you agree with this expected behavior?
sKopheK commentedon Jul 18, 2025
hello, @CNSeniorious000, thanks for the quick reply.
I'm ok with both suggested and current behavior, just need to know that provided JSON is malformed (not considering incomplete of course) - throwing an exception with whatever it parsed might work even though I have probably never seen such combination :).
sKopheK commentedon Jul 21, 2025
hi, found another, even more serious one: when there's space between empty array brackets, everything after this gets discarded:
example:
returns
empty space between curly brackets is fine
CNSeniorious000 commentedon Jul 21, 2025
Really thank you for discovering this!
I will be attending a hackathon starting tomorrow, but I will make sure to release a new version of this package that addresses these issues no later than July 30th.
Fix issue #12: Improve error handling for malformed JSON
joszamama commentedon Nov 23, 2026
Still present in 0.1.7 and on main (86fd4bc), Node.js 26. A minimal case for the "space between empty array brackets" report above, two documents, one per line. Paste into an empty folder:
Output:
In
parseArr(src/index.ts L125-L144) there is noskipBlank()afterindex++, so for[ ]the loop callsparseAny(), which reachesparseNumand throws a malformed-JSON error. Thecatchreturns the partial array becauseAllow.ARRis set, without consuming], so the enclosing array or object ends at that]and the rest of the input is ignored. AddingskipBlank()afterindex++(asparseObjdoes after{) fixes this case; PR #13 contains that line, if the rest of #13 or #19 needs more time.I found this with the Fandango fuzzer.