@anilkumarthakur/vue3-json-viewer

中文文档
0.6.0发布于 2026/07/16MITTypeScriptESM + CJS零依赖近 30 天下载 2760

A beautiful, customizable JSON viewer component for Vue 3 with TypeScript support, dark/light mode, expand/collapse controls, and syntax highlighting.

原始使用文档
文档目录9 节
  1. Features
  2. Demo
  3. Installation
  4. Setup
  5. Props
  6. Methods
  7. Example JSON Data Structure
  8. Demo
  9. TypeScript Support

Vue 3 JSON Viewer

This plugin provides a Vue 3 component for rendering and interacting with JSON data in a structured and visually appealing way. It supports features like dark mode, expanding and collapsing nested objects, and more.

Features

  • Dark Mode: Toggle between light and dark themes for better visibility.
  • Expandable/Collapsible Objects: Easily manage the visibility of deeply nested data.
  • Reusability: Customize the viewer using props for various use cases.
  • Highly Configurable: Control expanded state, dark mode, and data rendering.

Demo

Vue3 JSON Viewer Demo

Installation

Install the package using your preferred package manager:

# For npm
npm install @anilkumarthakur/vue3-json-viewer

# For yarn
yarn add @anilkumarthakur/vue3-json-viewer

# For bun
bun add @anilkumarthakur/vue3-json-viewer

# For pnpm
pnpm add @anilkumarthakur/vue3-json-viewer

Setup

Import and use the JsonViewer component in your Vue 3 application:

  1. Import the Stylesheet
    Make sure to import the styles in your component or globally:

    import '@anilkumarthakur/vue3-json-viewer/styles.css';
    
  2. Use the JsonViewer Component

    <script setup lang="ts">
      import { computed, ref } from 'vue';
      import { JsonViewer } from '@anilkumarthakur/vue3-json-viewer';
    
      // Sample JSON data to display
      const jsonData = {
        name: 'John Doe',
        age: 30,
        isActive: true,
        hobbies: ['reading', 'traveling', 'coding'],
        address: {
          street: '123 Main St',
          city: 'New York',
          coordinates: { latitude: 40.7128, longitude: -74.006 },
        },
        deepNestedObject: {
          level1: { level2: { level3: { level4: { deepKey: 'deep value' } } } },
        },
      };
    
      const isDarkMode = ref(true);
      const toggleDarkMode = () => (isDarkMode.value = !isDarkMode.value);
    
      const isExpanded = ref(true);
      const toggleExpanded = () => (isExpanded.value = !isExpanded.value);
    
      const computedExpanded = computed(() =>
        isExpanded.value ? 'expanded' : 'collapsed',
      );
    </script>
    
    <template>
      <button @click="toggleDarkMode">Toggle Dark Mode</button>
      <button @click="toggleExpanded">Toggle Expanded</button>
      <JsonViewer
        :data="jsonData"
        :expanded="isExpanded"
        :darkMode="isDarkMode"
        :key="computedExpanded"
      />
    </template>
    

Props

The JsonViewer component provides several props for customization:

PropTypeDefaultDescription
dataObject{}The JSON data to be rendered.
expandedBooleantrueWhether to expand all objects/arrays by default.
darkModeBooleanfalseEnable dark mode for the JSON viewer.
levelNumber0The depth level at which to start rendering the JSON object.

Methods

You can use methods within your Vue components to dynamically control the viewer:

  • toggleDarkMode: Toggles between light and dark themes.
  • toggleExpanded: Expands or collapses all objects/arrays.

Example JSON Data Structure

Here's an example of the type of JSON data you can render using the JsonViewer component:

const jsonData = {
  name: 'John Doe',
  age: 30,
  isActive: true,
  isVerified: false,
  hobbies: ['reading', 'traveling', 'swimming', 'coding'],
  items: [
    {
      property1: 'value',
      property2: 'value2',
      property3: 'value3',
    },
    {
      property1: 'value',
      property2: 'value2',
      property3: 'value3',
    },
  ],
  address: {
    street: '123 Main St',
    city: 'New York',
    state: 'NY',
    zipCode: '10001',
    coordinates: {
      latitude: 40.7128,
      longitude: -74.006,
    },
  },
  mixedArray: [1, 2, 3, 'test', { property: 'value' }],
  temperature: -2.757,
  currentDate: new Date(),
  regexPattern: /[0-9]/gi,
  formattedDate: Moment().format('YYYY-MM-DD'),
  emptyObj: {},
  emptyArr: [],
  emptyStr: '',
  zeroValue: 0,
  nullValue: null,
  undefinedValue: undefined,
  deepNestedObject: {
    level1: {
      level2: {
        level3: {
          level4: {
            level5: {
              deepKey: 'deep value',
            },
          },
        },
      },
    },
  },
  sampleFunction: function () {
    return 'This is a function';
  },
};

Demo

For a live demo, check out the example on Vercel or explore the demo in src/App.vue of the repository.

TypeScript Support

The JsonViewer component is fully typed, making it easier to work with in TypeScript projects.

Enjoy a seamless and customizable JSON viewing experience in your Vue 3 applications with @anilkumarthakur/vue3-json-viewer

版本与发布记录

@anilkumarthakur/vue3-json-viewer 共发布 20 个版本,首次发布于 2024/10/23;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.6.0latest2026/07/163 个月前
0.5.12026/04/047 个月前
0.5.02026/04/037 个月前
0.4.12026/01/189 个月前
0.4.02026/01/189 个月前
0.3.02025/07/131.3 年前

关于 @anilkumarthakur/vue3-json-viewer 的常见问题

@anilkumarthakur/vue3-json-viewer 是什么?

A beautiful, customizable JSON viewer component for Vue 3 with TypeScript support, dark/light mode, expand/collapse controls, and syntax highlighting.

如何安装 @anilkumarthakur/vue3-json-viewer?

在项目目录运行 npm install @anilkumarthakur/vue3-json-viewer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@anilkumarthakur/vue3-json-viewer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anilkumarthakur/vue3-json-viewer 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anilkumarthakur/vue3-json-viewer 可以商用吗?

@anilkumarthakur/vue3-json-viewer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@anilkumarthakur/vue3-json-viewer 的下载量有多少?

根据 npm 官方下载统计,@anilkumarthakur/vue3-json-viewer 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,760 次,日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anilkumarthakur/vue3-json-viewer 还在维护吗?

最新版本 0.6.0 发布于 2026/07/16(3 个月前);至今共发布 20 个版本,其中过去 12 个月发布了 5 个;首次发布于 2024/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。