Description
Hello! π
Have been on the hunt for better ways to return feedback with JSON.parse, and was thrilled to find this. Recently I hit a new-to-me error with JSON.parse
β you cannot do a parse against an empty string. It'll throw the following:
Uncaught SyntaxError: Unexpected end of JSON input
With json-parse-better-errors
it is better, but still a little cryptic:
SyntaxError: Unexpected end of JSON input while parsing near ''
Neither gives much feedback in terms of "hey, you just tried to pass me nothing." Much like the catch for the passing of a non-string or Array, do you think something like this would be within the scope of json-parse-better-errors
?
I'm not 100% sure what would be the best way to determine when something is truly an empty string, though. Maybe a combination of String.prototype.trim()
and a string.length
check?
Thanks for the useful library!