public function asJson(bool $pretty = false): string
    {
        $response = $this->compile();

        $options = 0;
        if ($pretty) {
            $options = \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT;
        }

        $json = json_encode($response, $options);

        if (false === $json) {
            throw JsonEncodeException::fromJsonError(\json_last_error(), $response);
        }

        return $json;
    }