final public function printJson(
        $prettyPrint = true,
        $depth = 512)
    {
        // NOTE: These options are important. For display purposes, we don't
        // want escaped slashes or `\uXXXX` hex versions of UTF-8 characters.
        $options = ($prettyPrint ? JSON_PRETTY_PRINT : 0) | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
        $json = $this->asJson($options, $depth); // Throws.
        if ($prettyPrint && PHP_EOL !== "\n") {
            // PHP's JSON pretty-printing uses "\n" line endings, which must be
            // translated for proper display if that isn't the system's style.
            $json = str_replace("\n", PHP_EOL, $json);
        }
        echo $json.PHP_EOL;
    }