Makes json pretty the json output.
Borrowed from http://www.php.net/manual/en/function.json-encode.php#80339

@param   string  $json  json encoded array
@return  string|false  pretty json output or false when the input was not valid
187161
protected function prettyJson($data)
	{
		$json = json_encode($data, Arr::get($this->config, 'json.encode.options', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP));

		if (json_last_error() !== JSON_ERROR_NONE)
		{
			return false;
		}

		$tab = "\t";
		$newline = "\n";
		$new_json = "";
		$indent_level = 0;
		$in_string = false;
		$len = strlen($json);

		for ($c = 0; $c < $len; $c++)
		{
			$char = $json[$c];
			switch($char)
			{
				case '{':
				case '[':
					if ( ! $in_string)
					{
						$new_json .= $char.$newline.str_repeat($tab, $indent_level+1);
						$indent_level++;
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case '}':
				case ']':
					if ( ! $in_string)
					{
						$indent_level--;
						$new_json .= $newline.str_repeat($tab, $indent_level).$char;
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case ',':
					if ( ! $in_string)
					{
						$new_json .= ','.$newline.str_repeat($tab, $indent_level);
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case ':':
					if ( ! $in_string)
					{
						$new_json .= ': ';
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case '"':
					if ($c > 0 and $json[$c-1] !== '\\')
					{
						$in_string = ! $in_string;
					}
				default:
					$new_json .= $char;
					break;
			}
		}

		return $new_json;
	}
609054
public static function decode($json)
    {
        $flags = 0;
        if (PHP_INT_SIZE === 4) {
            $flags |= JSON_BIGINT_AS_STRING;
        }
        $data = json_decode($json, false, 512, $flags);
        $error = json_last_error();
        if ($error !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException(sprintf('Failed to decode JSON (%d): %s.', $error, json_last_error_msg()));
        }

        return $data;
    }
1367582
public function toJSON($pretty = false)
    {
        if (!$pretty) {
            return json_encode($this->expose());
        } else {
            return $this->prettyPrint(json_encode($this->expose()));
        }
    }
330671
public function toJson($all = false)
    {
        return $all ? json_encode($this->getAllData()) : json_encode($this->toArray());
    }
739535
private function prettyPrint($json) {
        $tokens = preg_split('|([\{\}\]\[,])|', $json, -1, PREG_SPLIT_DELIM_CAPTURE);
        $result = '';
        $indent = 0;
        $ind = '  ';
        $lineBreak = "\n";

        $inLiteral = false;
        foreach ($tokens as $token) {
            if ($token == '') {
                continue;
            }
            $prefix = str_repeat($ind, $indent);
            if (!$inLiteral && ($token == '{' || $token == '[')) {
                $indent++;
                if (($result != '') && ($result[(strlen($result) - 1)] == $lineBreak)) {
                    $result .= $prefix;
                }
                $result .= $token . $lineBreak;
            } elseif (!$inLiteral && ($token == '}' || $token == ']')) {
                $indent--;
                $prefix = str_repeat($ind, $indent);
                $result .= $lineBreak . $prefix . $token;
            } elseif (!$inLiteral && $token == ',') {
                $result .= $token . $lineBreak;
            } else {
                $result .= ($inLiteral ? '' : $prefix) . $token;
                // Count # of unescaped double-quotes in token, subtract # of
                // escaped double-quotes and if the result is odd then we are
                // inside a string literal
                if ((substr_count($token, "\"") - substr_count($token, "\\\"")) % 2 != 0) {
                    $inLiteral = !$inLiteral;
                }
            }
        }
        return $result;
    }
1195629
protected static function prettyPrint($json)
    {
        $result = '';
        $pos = 0;
        $indentation = '    ';
        $newline = "\n";
        $previousChar = '';
        $outOfQuotes = true;

        // Unescape slashes.
        if (strpos($json, '/')) {
            $json = preg_replace('#\134{1}/#', '/', $json);
        }

        $stringLength = strlen($json);

        for ($i = 0; $i <= $stringLength; $i++) {

            // Grab the next character in the string.
            $char = substr($json, $i, 1);

            if (':' == $previousChar && $outOfQuotes) {
                $result .= ' ';
            }

            // Are we inside a quoted string?
            if ('"' == $char && $previousChar != '\\') {
                $outOfQuotes = !$outOfQuotes;

                // If this character is the end of an element,
                // output a new line and indent the next line.
            } elseif (('}' == $char || ']' == $char) && $outOfQuotes) {
                $result .= $newline;
                $pos --;
                for ($j = 0; $j < $pos; $j++) {
                    $result .= $indentation;
                }
            }

            // Add the character to the result string.
            $result .= $char;

            // If the last character was the beginning of an element,
            // output a new line and indent the next line.
            if ((',' == $char || '{' == $char || '[' == $char) && $outOfQuotes) {
                $result .= $newline;
                if ('{' == $char || '[' == $char) {
                    $pos ++;
                }

                for ($j = 0; $j < $pos; $j++) {
                    $result .= $indentation;
                }
            }

            $previousChar = $char;
        }

        return $result;
    }
134360
public function decode($json)
    {
        // Clear the path array.
        $this->paths = array();
        // Decode the given JSON data if necessary.
        $x = is_string($json) ? json_decode($json) : $json;
        // Get all data paths.
        $this->getPaths($x);
        // Resolve all path references.
        $this->resolvePathReferences($x);
        // Return the data.
        return $x;
    }
81131
public function toAmp(string $json)
    {
        if (empty($this->view)) {
            $this->view = 'sirtrevorjs::amp';
        }

        $this->output = 'amp';

        return $this->convert($json, false);
    }
969961
protected function prepare_json_content( $content ) {
		if ( $content instanceof Jsonable ) {
			return $content->toJson();
		}

		if ( $content instanceof Arrayable ) {
			return json_encode( $content->toArray() );
		}

		return json_encode( $content );
	}
703269
public static function isJson($string)
    {
        if (!is_string($string) || (is_string($string)
                && substr($string, 0, 1) !== '{'
                && substr($string, 0, 1) !== '[')
        ) {
            return false;
        }
        @json_decode($string);
        return (json_last_error() == JSON_ERROR_NONE);
    }
913497
public static function jsonDecode($string)
    {
        if ($string) {
            $json = json_decode($string, true);
            // if json_decode failed
            if ($json === null) {
                self::jsonLastError();
            }
            return $json;
        } else {
            return false;
        }
    }
1234919
def pretty_json(data):
    
    data = json.loads(data.decode('utf-8'))
    return json.dumps(data, indent=4, sort_keys=True)
58352
public function getJson(bool $pretty = false)
    {
        if ($pretty) {
            return \json_encode($this->ediGroups, JSON_PRETTY_PRINT);
        }

        return \json_encode($this->ediGroups);
    }
830840
public static function jsonEncode($data)
    {
        $json = json_encode($data);
        // if json_encode failed
        if ($json === false) {
            self::jsonLastError();
        }
        return $json;
    }
1338730
public function json($pretty=FALSE) {
		if($pretty) {
			$sorted = $this->payload;
			$this->sortRecursive($sorted);
			return json_encode($sorted, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
		} else {
			return json_encode($this->payload);
		}
	}
1143673
public function decode(string $json)
    {
        // max depth is 0+ for json_encode(), and 1+ for json_decode()
        $result = json_decode($json, $this->decodeObjectAsArray, $this->maxDepth + 1, $this->options);

        $this->checkLastError();

        return $result;
    }
1036006
public function decode($json)
    {
        if (empty($json)) {
            return '';
        }
        $decoded = json_decode($json, true);
        if (null !== $decoded) {
            return $decoded;
        }
        if (JSON_ERROR_NONE === json_last_error()) {
            return $json;
        }

        return self::$jsonErrors[json_last_error()];
    }