Render JSON Data As Collapsible Tree - jQuery simpleJson

Render JSON Data As Collapsible Tree - jQuery simpleJson
File Size: 6.93 KB
Views Total: 259
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A simple and fast JSON viewer plugin that can present complex JSON data as a nested, collapsible, human-readable tree structure.

See Also:

How to use it:

1. Insert the jQuery simpleJson plugin's files into the page.

<link rel="stylesheet" href="/path/to/css/simpleJson.css" />
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/js/simpleJson.js"></script>

2. Create a container to hold the JSON tree.

<div id="example"></div>

3. Initialize the plugin on the tree container and define your own JSON data as follows.

const myData = [
      {
        color: "red",
        value: "#f00"
      },
      {
        color: "green",
        value: "#0f0"
      },
      {
        color: "blue",
        value: "#00f"
      },
      {
        color: "cyan",
        value: "#0ff"
      },
      {
        color: "magenta",
        value: "#f0f"
      },
      {
        color: "yellow",
        value: "#ff0"
      },
      {
        color: "black",
        value: "#000"
      }
]
$("#example").empty().simpleJson({ 
  jsonObject: myData 
});

4. Customize the collpased text. Default: '...'.

$("#example").empty().simpleJson({ 
  jsonObject: myData,
  collapsedText: "......"
});

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