Why does JSON parsing not fail on the first character for strings starting with "t"?

The keyword true starts with "t". Thus until the parser sees the "e", it doesn't know the syntax is invalid.

The error is somewhat fascinating because it reports "e" as being a token, which is not the way I'd implement a JSON parser. That seems to be a Node/V8 thing, as Firefox rejects the whole token starting from position 1 (the "t").

You can double-check this answer by trying JSON.parse("nulp"); Node errors on the "p".


The full JSON syntax is as follows:

JSON = null
    or true or false
    or JSONNumber
    or JSONString
    or JSONObject
    or JSONArray

so the compiler will deal with t, n , f as a valid start for a JSON string. for more information check: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse