jquery plugin to make JSON more human-readable
A simple, light-weight jquery plugin that makes your JSON messages easier to read.
I have done quite a thorough test on it and it works perfectly so far, if you come across a JSON format that it does not "beautify" properly, please post it on the issues page.
Plain: https://cdn.rawgit.com/obedtandadjaja/beautify-json/master/index.html
- Handles incomplete/non-formatted JSON format (accepts JSON with a few missing brackets here and there)
- Done all in the paragraph tag using whitespaces and breaks
- Non-collapsible
- No color coding
- Very lightweight
- Demo: https://cdn.rawgit.com/obedtandadjaja/beautify-json/master/plain.html
- Handles incomplete/non-formatted JSON format (accepts JSON with a few missing brackets here and there)
- Done with nested divs, uls, and lis
- Collapsible and hoverable
- No color coding for different types
- Demo: https://cdn.rawgit.com/obedtandadjaja/beautify-json/master/flexible.html
- Handles only perfectly formatted JSON, if not then show error
- Done with nested divs, uls, and lis
- Collapsible and hoverable
- Color coding for different types
- Demo: https://cdn.rawgit.com/obedtandadjaja/beautify-json/master/strict.html
- Type
$(document).ready(function(){
$('.json').beautifyJSON({
type: "plain" // strict, plain, or flexible; default is strict
});
});
- Collapsible
$(document).ready(function(){
$('.json').beautifyJSON({
collapsible: true
});
});
- Hoverable
$(document).ready(function(){
$('.json').beautifyJSON({
hoverable: true
});
});
- Color-code
$(document).ready(function(){
$('.json').beautifyJSON({
color: true
});
});
- Clone this repository or download the file
jquery.beautify-json.js
- In your html file, make sure you have a script tag for
jquery.min.js
andjquery.beautify-json.js
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="jquery.beautify-json.js"></script>
- Have your JSON under any HTML tag
<p>JSON data...</p>
<h1>JSON data...</h1>
<div class="json">JSON data...</div>
- Call the beautify method to the HTML tag or id/class you specified
<script>
$(document).ready(function()
{
$('p').beautifyJSON();
$('.json').beautifyJSON();
});
</script>
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.