JSON.parse & MochiKit.Base.evalJSON

10 views
Skip to first unread message

Per Cederberg

unread,
Nov 28, 2009, 5:18:38 PM11/28/09
to MochiKit
I just tried to modify MochiKit.Base.evalJSON() to use the new
JSON.parse() function when available. This would give us the following
advantages:

1. Speed (but, well... eval() is probably fast enough already)
2. Security

Unfortunately we would also get a nasty regression issue due to the
stricter syntax enforcement in JSON.parse() vs. eval(). It seems that
at least the Firefox parser doesn't accept constructs like these:

{ a: 1 }

since the correct JSON syntax would be:

{ "a": 1 }

Hmm... So what to do? Just skip this altogether? And add a note in the
docs that people should use JSON.parse() themselves if worried about
security or speed?

Any thoughts are welcome.

Cheers,

/Per

Bob Ippolito

unread,
Jan 2, 2010, 7:24:58 PM1/2/10
to Per Cederberg, MochiKit
On Sat, Nov 28, 2009 at 2:18 PM, Per Cederberg <cede...@gmail.com> wrote:
> I just tried to modify MochiKit.Base.evalJSON() to use the new
> JSON.parse() function when available. This would give us the following
> advantages:
>
> 1. Speed (but, well... eval() is probably fast enough already)
> 2. Security
>
> Unfortunately we would also get a nasty regression issue due to the
> stricter syntax enforcement in JSON.parse() vs. eval().

None of the apps we've written depend on the capability to parse
invalid JSON, so it wouldn't bother me.

-bob

Reply all
Reply to author
Forward
0 new messages