/**
  * Export to JSON if requested
  */
 protected function handleFormatRequest($query = null)
 {
     if ($this->params->get('format') === 'json' || $this->getRequest()->getHeader('Accept') === 'application/json') {
         $payload = (array) $this->object->properties;
         $payload += array('contacts' => $this->object->contacts->fetchPairs(), 'contact_groups' => $this->object->contactgroups->fetchPairs(), 'vars' => $this->object->customvars);
         $groupName = $this->object->getType() . 'groups';
         $payload[$groupName] = $this->object->{$groupName};
         $this->getResponse()->json()->setSuccessData($payload)->sendResponse();
     }
 }