Beautiful JSON Viewer Editor - Download Beautiful JSON Viewer And Editor With jQuery - JSON Editor

Download Beautiful JSON Viewer And Editor With jQuery – JSON Editor

Posted on

This time I will share jQuery Plugin and tutorial about Beautiful JSON Viewer And Editor With jQuery – JSON Editor, hope it will help you in programming stack.

Beautiful JSON Viewer Editor - Download Beautiful JSON Viewer And Editor With jQuery - JSON Editor
File Size: 8.94 KB
Views Total: 28839
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A lightweight, simple, beautiful JSON viewer and editor plugin inspired by Abodelot’s jQuery JSON Viewer.

The JSON editor helps the developers to render JSON objects in HTML with collapsible/expandable navigation just like a tree view.

Syntax highlighting is supported as well.

How to use it:

1. Create a normal textarea element for the JSON editor.

01 <textarea id="json-input" autocomplete="off">
02   {
03     "id": 1001,
04     "type": "donut",
05     "name": "Cake",
06     "description": "http://en.wikipedia.org/wiki/Doughnut",
07     "price": 2.55,
08     "available": {
09       "store": 42,
10       "warehouse": 600
11     },
12     "topping": [
13       { "id": 5001, "type": "None" },
14       { "id": 5002, "type": "Glazed" },
15       { "id": 5005, "type": "Sugar" },
16       { "id": 5003, "type": "Chocolate" },
17       { "id": 5004, "type": "Maple" }
18     ]
19   }
20 </textarea>

2. Create an empty container for the JSON viewer.

1 <pre id="json-display"></pre>

3. Create a button that will translte the JSON data into HTML.

1 <button id="translate">Translate</button>

4. Put jQuery library and the jQuery JSON Editor plugin at the bottom of your page.

2         integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
3         crossorigin="anonymous"></script>
4 <script src="jquery.json-editor.min.js"></script>

5. The JavaScript to enable the JSON editor.

01 // get JSON
02 function getJson() {
03   try {
04     return JSON.parse($('#json-input').val());
05   } catch (ex) {
06     alert('Wrong JSON Format: ' + ex);
07   }
08 }
09  
10 // initialize
11 var editor = new JsonEditor('#json-display', getJson());
12  
13 // enable translate button
14 $('#translate').on('click', function () {
15   editor.load(getJson());
16 });

This awesome jQuery plugin is developed by dblate. For more Advanced Usages, please check the demo page or visit the official website.

source : jquery.net