Vue JSON Tree

0.4.3 · maintenance · verified Sun Apr 19

vue-json-tree is a Vue 2 component designed to display JavaScript Object Notation (JSON) data in an interactive, collapsible tree structure. Currently at version 0.4.3, the package appears to have an irregular release cadence, indicative of a pre-1.0 project primarily maintained for existing Vue 2 applications. Its key differentiator lies in its straightforward integration within Vue 2 ecosystems, offering both string-based (`raw` prop) and pre-parsed object-based (`data` prop) input methods. This flexibility allows developers to easily visualize complex JSON structures, with options to control the initial expansion level. It focuses specifically on the display aspect, without editing capabilities, making it a lightweight solution for debugging or data inspection within Vue 2 applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate and use `vue-json-tree` within a Vue 2 application using browser script tags, showcasing both `raw` (JSON string) and `data` (parsed object) props, along with initial collapse level for nested data.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vue JSON Tree Quickstart</title>
  <style>
    body { font-family: sans-serif; margin: 20px; }
    #app { border: 1px solid #eee; padding: 15px; border-radius: 5px; max-width: 600px; margin-top: 20px; }
  </style>
</head>
<body>
  <h1>Vue JSON Tree Demonstration</h1>
  <p>This example showcases the <code>vue-json-tree</code> component rendering a complex JSON object.</p>
  <div id="app"></div>

  <!-- Include Vue 2 -->
  <script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
  <!-- Include vue-json-tree -->
  <script src="https://unpkg.com/vue-json-tree@0.4.1/dist/json-tree.js"></script>

  <script>
    new Vue({
      template: `
        <div>
          <h2>Product Catalog Data</h2>
          <json-tree :raw="catalogData" :level="1"></json-tree>
          <hr>
          <h2>User Profile Data</h2>
          <json-tree :data="userData"></json-tree>
        </div>
      `,
      el: '#app',
      data: {
        catalogData: JSON.stringify({
          products: [
            {
              id: "P001",
              name: "Laptop Pro X15",
              category: "Electronics",
              price: 1200.00,
              features: ["16GB RAM", "512GB SSD", "Intel i7"],
              available: true,
              manufacturer: {
                name: "TechCorp",
                country: "USA"
              },
              reviews: [
                { user: "Alice", rating: 5, comment: "Fantastic machine!" },
                { user: "Bob", rating: 4, comment: "Good, but a bit pricey." }
              ]
            },
            {
              id: "P002",
              name: "Wireless Earbuds",
              category: "Accessories",
              price: 89.99,
              features: ["Bluetooth 5.0", "Noise Cancelling"],
              available: false,
              manufacturer: {
                name: "AudioTech",
                country: "China"
              }
            }
          ],
          lastUpdated: new Date().toISOString()
        }, null, 2),
        userData: {
          username: "developer_user",
          email: "dev@example.com",
          roles: ["admin", "editor"],
          settings: {
            theme: "dark",
            notifications: {
              email: true,
              push: false
            }
          },
          lastActivity: new Date().toISOString(),
          preferences: {
            language: "en-US",
            timezone: "UTC"
          }
        }
      }
    });
  </script>
</body>
</html>

view raw JSON →