Take the tour ×  I need to encode a javascript function into a
JSON object in PHP.   $function = "function(){}"; $message =
"Hello";  $json = array(          'message' => $message,
'func' => $function echo json_encode($json);    What I want is:
Can I do this with json_encode?  share|improve this question add
comment  4 Answers  up vote 8 down vote accepted  As Jani said,
this is not possible directly with JSON, but this might help you
: http://solutoire.com/2008/06/12/sending-javascript-functions-
over-json/  share|improve this answer That works, although it's
not really JSON anymore. –  Matthew Crumley Nov 17 '09 at 3:12
It is a valid JavaScript/Jscript/ECMAScript object, right? – 
David Murdoch Nov 17 '09 at 18:26 Yes, as long as you parse it
with eval instead of using a strict JSON parser. –  Matthew
Crumley Nov 18 '09 at 2:53 add comment  No. JSON spec does not
support functions. You can write your own code to output it in a
JSON-like format and it should work fine though.  share|improve
this answe