(mootools) JSON.encode Vs (json2-json.org) JSON.stringify

12 views
Skip to first unread message

Roman Land

unread,
Nov 25, 2009, 10:13:03 AM11/25/09
to mootool...@googlegroups.com
Hi,

I was under the assumption that MooTools "encode" is functionality-wise compatible with the json2 JS library from http://www.json.org/js.html.

There is a bug (?) where when a form field (or any object parameter value..) is equal to " (single double quote) the result of (mootools') JSON.encode will not escape it, ie:

var a = 'this is " a double quote'
JSON.encode(a) == 'this is " a double quote'

While if I use the JSON2 library from json.org the result would be as expected: (note the same name space JSON..)

JSON.stringify(a) == 'this is \" a double quote'

Is this a "feature" or a bug? :)
My vote goes for a bug, since if I am using mootools and encoding a form into JSON to be sent to a server, and the user used a single double quote (sometimes legitimately used as part of a name) will cause an error...

What say you?

Cheers,
Roman

--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein

Reply all
Reply to author
Forward
0 new messages