Page 1 of 1

force json_encode not to put quotes

Posted: Wed Feb 10, 2010 6:17 am
by vassy
Hello.

I need to force json_encode NOT to put any quotes around certain values.
Example:

Code: Select all

 
$ar = array(
'data' => '$(this).val()'
);
 
json_encode returns:

Code: Select all

 
{"data":"$(this).val()"}
 
and $(this).val() doesn't get executed by javascript when I publish this result on a page.

Is it possible to tell json_encode not to enclose some values with quotes?
Like when it doesn't do that for integers.

Thank you!

Re: force json_encode not to put quotes

Posted: Wed Feb 10, 2010 9:52 am
by pickle
It's not legitimate/valid JSON unless everything's in quotes - so you're likely not going to get away from that. You could try eval()-ing what needs to be executed as Javascript.