The point about the error position is the one that saves the most time. The parser points at where it gave up, so a missing comma on the line above shows up as an error on the next key. Worth adding: JSON.parse also chokes on a BOM at the start of a file read from disk, and the error for that is fairly cryptic.
Thanks, that's exactly it. The parser reports where it gave up, not where the mistake is, so the line just above is usually the culprit. Great point on the BOM too. It's invisible in most editors and the error message gives no hint, so stripping it first (or re-saving as UTF-8 without BOM) saves a lot of head-scratching. I'll add it to the post.
Good call adding it. A one-line check that strips a leading BOM before parsing would make a nice small snippet next to it, since that is the fix people will want to copy.
StackShortlist
The point about the error position is the one that saves the most time. The parser points at where it gave up, so a missing comma on the line above shows up as an error on the next key. Worth adding: JSON.parse also chokes on a BOM at the start of a file read from disk, and the error for that is fairly cryptic.