The short answer is "no".
What I've done in the past to solve this sort of problem is to write a special getter that returns an associative array (or object) in the format you want, then call json_encode on the return value. In your case, it might be implemented something like this:
function get_data()
{
$values = array('data' => $this->data);
if($this->children) {
$values['children'] = array();
foreach($this->children as $child)
$values['children'][] = $child->get_data();
}
}
Here I'm assuming that $children is an array of TreeNode objects (or null).
Then you would call it like this:
json_encode($node->get_data());
HTH,
-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837