JBZoo\Data\JSON::_render PHP Method

_render() protected method

Do the real json encoding adding human readability. Supports automatic indenting with tabs
protected _render ( array | object $data, integer $indent ) : string
$data array | object The array or object to encode in json
$indent integer The indentation level. Adds $indent tabs to the string
return string
    protected function _render($data, $indent = 0)
    {
        if (defined('JSON_PRETTY_PRINT')) {
            return json_encode($data, JSON_PRETTY_PRINT);
        }
        if (count($data) == 0) {
            return '[]';
        }
        $result = '';
        foreach ($data as $key => $value) {
            $result .= str_repeat('    ', $indent + 1);
            $result .= json_encode((string) $key) . ': ';
            $isComplex = is_object($value) || is_array($value);
            $result .= $isComplex ? $this->_render($value, $indent + 1) : json_encode($value);
            $result .= ',' . Data::LE;
        }
        if (!empty($result)) {
            $result = substr($result, 0, -2);
        }
        $result = '{' . Data::LE . $result;
        $result .= Data::LE . str_repeat('    ', $indent) . '}';
        return $result;
    }