public static function buildObject($var, $format = false){
        if (is_array($var)) {
            $returnValue = '{';
            $i = 1;
            foreach($var as $k => $v){
                $k = is_int($k)?'"'.json_encode($k).'"':json_encode($k);
                $returnValue .= $k.':'.self::buildObject($v, $format);
                $returnValue .= ($i < count($var)) ? ',' : '';
                $returnValue .= $format ? PHP_EOL : '';
                $i++;
            }
            $returnValue .= '}';
        } else {
            
            // Some versions of PHP simply fail
            // when encoding non UTF-8 data. Some other
            // versions return null... If it fails, simply
            // reproduce a single failure scenario.
            $returnValue = @json_encode($var);
            
            if ($returnValue === false) {
                $returnValue = json_encode(null);
            }
        }
        
        return $returnValue;
    }