protected function jsonEncode($element): string
    {
        $json = json_encode($element, $this->options);

        if ($json === false) {
            trigger_error("JSON encode failed; " . json_last_error_msg(), E_USER_WARNING);
            return json_encode(null);
        }

        // Indent for pretty print
        if (($this->options & \JSON_PRETTY_PRINT) > 0 && (~$this->options & self::OUTPUT_LINES) > 0) {
            $json = rtrim("    " . str_replace("\n", "\n    ", $json));
        }

        return $json;
    }