The JSON specification is now wrong

Monday, 25 July 2011

ES5 has decided for whatever reason to treat \u2028 and \u2029 (line/paragraph separators) as a new line in JavaScript this makes it in-line with regex “\s” character class. The JSON specification (to my knowledge) wasn’t changed. So although it mentions escaping characters within strings it isn’t a requirement. This means we’re left with \u2028 and \u2029 characters that can break entire JSON feeds since the string will contain a new line and the JavaScript parser will bail out.

Another interesting fact is that Crockford’s regex in the JSON specification is also wrong, correct at the time but now wrong =)

You do not put anything there, the intention is to bail out the page serving the JSON. So a server side JSON parser would likely leave 0x2028/x02029 and when the page is served a syntax error would occur since the string will be broken with a new line.