function output()
 {
     $a_formElsToAdd = array();
     $a_formRulesToAdd = array();
     $this->o_form = new JsonFormBuilder($this->modx, $this->getJsonVal($this->a_json, 'id', true));
     $a_ignore = array('id', 'elements');
     foreach ($this->a_json as $key => $val) {
         if (in_array($key, $a_ignore)) {
             continue;
         }
         $methodName = 'set' . ucfirst($key);
         $this->o_form->{$methodName}($val);
     }
     $a_elements = $this->getJsonVal($this->a_json, 'elements', true);
     foreach ($a_elements as $element) {
         if (is_array($element) === false && empty($element) === false) {
             $a_formElsToAdd[] = $element;
         } else {
             $elementMethod = 'JsonFormBuilder_element' . ucfirst($this->getJsonVal($element, 'element', true));
             //required to set id and label in constructors.. all elements have id and label
             $o_el = new $elementMethod($element['id'], $element['label']);
             $a_ignore = array('element', 'rules', 'id', 'label');
             foreach ($element as $key => $val) {
                 if (in_array($key, $a_ignore)) {
                     continue;
                 }
                 $methodName = 'set' . ucfirst($key);
                 $o_el->{$methodName}($val);
             }
             $a_formElsToAdd[] = $o_el;
             //add rules if needed
             $a_rules = $this->getJsonVal($element, 'rules');
             if ($a_rules) {
                 foreach ($a_rules as $rule) {
                     if (is_array($rule)) {
                         //rule in assoc array
                         $r = new FormRule($rule['type'], $o_el, $rule['value']);
                         $a_ruleignore = array('type');
                         foreach ($rule as $key => $val) {
                             if (in_array($key, $a_ruleignore)) {
                                 continue;
                             }
                             $methodName = 'set' . ucfirst($key);
                             $r->{$methodName}($val);
                         }
                     } else {
                         //simple rule
                         $r = new FormRule($rule, $o_el);
                     }
                     $r->refresh();
                     // just in case
                     $a_formRulesToAdd[] = $r;
                 }
             }
         }
     }
     $this->o_form->addRules($a_formRulesToAdd);
     $this->o_form->addElements($a_formElsToAdd);
     return $this->o_form->output();
 }