This project is archived and is in readonly mode.

#494 ✓invalid
Eineki

JSON.decode fail to recognise a JSON object

Reported by Eineki | November 22nd, 2008 @ 05:38 PM | in 2.0 (closed)

The decode function of JSON in the 1.2 release throws an error in IE6: return null on a call with this signature


JSON.decode("{first:'dummy', second:'third'}", true);

obviously


Json.decode("{first:'dummy', second:'third'}")

Return the correct, I hope, object.

When a syntax check is required the regular expression in the line below fails on that JSON string


if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*
$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '')))
return null;

Comments and changes to this ticket

  • digitarald

    digitarald November 22nd, 2008 @ 06:16 PM

    Validating your code in http://www.jsonlint.com/ shows your error: Every string (keys and values!) have to be in ", not without and not with '. Eval can still handle it, but every other JSON decoder will choke on it (and the validator will not call it a valid input).

    Your mistake: don't build JSON on your own, use a JSON encoder that available for all languages (ref http://json.org/)

    Can be closed.

  • Jan Kassens

    Jan Kassens November 22nd, 2008 @ 06:42 PM

    • State changed from “new” to “invalid”

    as harald said, not a valid json string according to json.org (since the validator is based upon their validator, i think)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages