Last active
December 14, 2015 10:39
-
-
Save kristopherjohnson/5073681 to your computer and use it in GitHub Desktop.
A Web Page for Reformatting JSON Text
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<!-- | |
Copyright (c) 2013 Kristopher Johnson | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to | |
permit persons to whom the Software is furnished to do so, subject to | |
the following conditions: | |
The above copyright notice and this permission notice shall be | |
included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
--> | |
<head> | |
<meta charset="utf-8" /> | |
<title>JSON Reformatter</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function() { | |
$('#formatButton').click(function () { | |
try { | |
var inputJSON = $('#inputJSON').val(), | |
parsedData = JSON.parse(inputJSON), | |
outputJSON = JSON.stringify(parsedData, null, ' '); | |
$('#outputJSON').val(outputJSON); | |
} catch (err) { | |
$('#outputJSON').val('Error: ' + err.message); | |
} | |
}) | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>JSON Reformatter</h1> | |
<p> | |
Paste your JSON into the top text box, then press the <strong>Format</strong> button to generate equivalent nicely formatted JSON in the lower text box. | |
</p> | |
<form> | |
<textarea | |
id="inputJSON" | |
rows="10" | |
cols="80" | |
placeholder="JSON Input" | |
autofocus="true" | |
></textarea> | |
<br> | |
<input | |
id="formatButton" | |
type="button" | |
value="Format"> | |
<br> | |
<textarea | |
id="outputJSON" | |
rows="10" | |
cols="80" | |
placeholder="JSON Output" | |
readonly="true" | |
></textarea> | |
</form> | |
</body> | |
</html> |
For a similar page implemented using AngularJS, see https://gist.github.com/kristopherjohnson/176dc5cc09dfc77cd4a6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See details here: http://undefinedvalue.com/2013/03/02/web-page-reformatting-json-text