views:

366

answers:

2

I need to send full objects from Javascript to PHP. It seemed pretty obvious to do JSON.stringify() and then json_decode() on the PHP end, but will this allow for strings with ":" and ","? Do I need to run an escape() function on big user input strings that may cause an issue? What would that escape function be? I don't think escape works for my purposes.

Are there any downsides to JSON.stringify() I need to know about?

Thanks

A: 

There is a pretty good description of what JSON.stringify() does here:

http://www.json.org/js.html

The shource code is also available if you want to be certain and/or make changes.

I've been using it for months without propblem.

Also, I'm not sure if you have seen the man page for json_decode, lots of good info there aswell: http://ie2.php.net/manual/en/function.json-decode.php

HTH

DannyLane
+2  A: 

Yes, it's reliable in any decent implementation (like Crockford's), and no, you don't have to run it through escape first (if you do that, PHP will be pretty confused at the other end). Browsers are starting to get their own implementations of JSON stuff (now that it's in the 5th edition spec), but for now, you may be best off using Crockford's or similar.

T.J. Crowder