, , , , ,

With the proliferation of Web 2.0 sites it is inevitable that the use XML or JSON to transfer your data to and fro your server become increasingly popular, especially the latter because of its more compact size (as compared with XML).

You normally accept your JSON data by parsing a valid JSON string, but there is a Mozilla Firefox bug that fails to evaluate your valid JSON string even if online parsers certify that your string is valid, for instance:

{code:63, name:"Philippines"}

is a valid JSON string but if you try to evaluate it in Firefox (normally by using eval()) you’ll get an “invalid label” error.  Why does this happen?  Firefox thinks that the part with a colon (code:) is a JavaScript label thus generating the error.


By simply wrapping your JSON string in parenthesis this problem is resolved; try evaluating this piece of JavaScript code:

({code:63, name:"Philippines"})

Voila!  Your JSON string evaluates properly as expected.