Vue JSON Viewer Component

1.3.0 · active · verified Wed Apr 22

vue-json-views is a Vue component designed for efficiently displaying large JSON data structures. Currently at version 1.3.0, its primary differentiator is optimized rendering performance, claiming fast load times for JSON files up to 1MB, which addresses common slowdowns experienced with other JSON viewer components when dealing with extensive node counts. The library provides fundamental viewing capabilities with several configurable options, including initial collapse state, display depth, theme selection (one-dark, vs-code), icon styles, font size, and line height. While a specific release cadence isn't documented, its version history suggests active maintenance. It aims to offer a performant and customizable solution for integrating JSON visualization directly into Vue applications, contrasting with heavier alternatives or those tied to other frameworks.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and register `vue-json-views` in a Vue 3 application, passing a complex JSON object as data. It showcases several configurable props like initial collapse state, display depth, icon style, theme, and font size. The example includes a large array within the JSON to highlight the component's performance focus.

import { createApp } from 'vue';
import jsonView from 'vue-json-views';

const app = createApp({
  components: {
    jsonView
  },
  data() {
    return {
      // Example large JSON data for demonstration
      json: {
        id: 1,
        name: 'Product A',
        details: {
          price: 99.99,
          currency: 'USD',
          features: [
            { key: 'material', value: 'plastic' },
            { key: 'weight', value: '100g' },
            { key: 'color', value: 'blue' }
          ],
          reviews: Array(500).fill(null).map((_, i) => ({ user: `User${i}`, rating: Math.floor(Math.random() * 5) + 1, comment: `Good product review ${i}` }))
        },
        metadata: {
          createdAt: '2023-01-01',
          updatedAt: '2023-04-20'
        },
        relatedProducts: Array(10).fill(null).map((_, i) => ({ id: i + 2, name: `Product ${String.fromCharCode(66 + i)}` }))
      }
    };
  },
  template: `
    <div style="height: 500px; overflow: auto; border: 1px solid #ccc; padding: 10px;">
      <h1>JSON Data Viewer</h1>
      <json-view
        :data="json"
        :closed="false"
        :deep="3"
        icon-style="triangle"
        theme="one-dark"
        :font-size="16"
      />
    </div>
  `
});

app.mount('#app');

view raw JSON →