What is the simplest and best practice way to customise the JSON output in cakephp 2.x.
I have the following in my controller:
$questions = $this->Question->find('threaded', array(
'fields' => array(
'label',
'id',
'parent_id',
'load_on_demand'
),
'order' => array('lft ASC')
));
$questions= $this->set('questions', $questions);
$this->set('_serialize', 'json');
I have the following JSON (truncated);
{
"Question": {
"id": "27",
"parent_id": "0",
"load_on_demand": "true",
"label": "Main Menu"
},
"children": [
{
"Question": {
"id": "28",
"parent_id": "27",
"load_on_demand": "true",
"label": "Web Development"
},
but I need it to be like the following example in jqTree;
{
label: 'node1',
children: [
{ label: 'child1' },
{ label: 'child2' }
]
},
{
label: 'node2',
children: [
{ label: 'child3' }
]
}