Created
October 9, 2012 17:32
-
-
Save suneil/3860216 to your computer and use it in GitHub Desktop.
JSON Pretty Printer in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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