Skip to content

Instantly share code, notes, and snippets.

@suneil
Created October 9, 2012 17:32
Show Gist options
  • Select an option

  • Save suneil/3860216 to your computer and use it in GitHub Desktop.

Select an option

Save suneil/3860216 to your computer and use it in GitHub Desktop.
JSON Pretty Printer in PHP
<?php
// works in php 5.4 only (JSON_PRETTY_PRINT for json_encode is a 5.4 feature)
$json = '';
if (isset($_POST['json_text']) && !empty($_POST['json_text'])) {
$struct = json_decode($_POST['json_text'], true);
$json = json_encode($struct, JSON_PRETTY_PRINT);
header('Content-Type: text/plain');
echo $json;
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>JSON Formatter</title>
</head>
<body>
<div>
<strong>Enter your shit json in here and click submit to get human readable json!</strong>
</div>
<form action="" method="POST">
<textarea name="json_text" style="width: 900px; height: 500px;"></textarea>
<input type="submit" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment