Vue3 JSON Editor

1.1.5 · active · verified Sun Apr 19

vue3-json-editor is a Vue.js 3 component that provides an interactive JSON editor. It's a direct fork of the `vue-json-editor` library, specifically tailored for Vue 3 applications, distinguishing it from older Vue 2 compatible versions. The package, currently at version 1.1.5, allows developers to display and edit JSON objects within their Vue components, supporting various modes like 'tree', 'view', and 'form'. It offers features such as displaying save buttons, expanding the editor on start, and handling different languages. The component provides `v-model` binding for the JSON data and emits events for changes (`json-change`), saves (`json-save`), and errors (`has-error`). It supports modern module systems including ESM and CommonJS, making it compatible with various build setups like Vite and webpack. While no explicit release cadence is stated, updates appear to be driven by maintenance and new feature integration from its upstream source.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `vue3-json-editor` into a Vue 3 component using the Composition API, binding a JSON object with `v-model` and handling change and error events.

<template>
  <div>
    <p>JSON Editor Example</p>
    <Vue3JsonEditor
      v-model="json"
      :show-btns="true"
      :expandedOnStart="true"
      mode="tree"
      @json-change="onJsonChange"
      @has-error="onJsonError"
    />
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from 'vue'
import { Vue3JsonEditor } from 'vue3-json-editor'

export default defineComponent({
  components: {
    Vue3JsonEditor
  },
  setup () {
    const state = reactive({
      json: { 
        name: "John Doe", 
        age: 30, 
        isStudent: false, 
        courses: ["Math", "Science"] 
      }
    })

    function onJsonChange (value: object) {
      console.log('JSON has changed:', value)
      // You might want to update the reactive 'json' state here if not using v-model directly.
    }

    function onJsonError (error: any) {
      console.error('JSON error:', error)
    }

    return {
      ...toRefs(state),
      onJsonChange,
      onJsonError
    }
  }
})
</script>

<style>
/* Basic styling for demonstration */
body { font-family: sans-serif; margin: 20px; }
div { max-width: 800px; margin: 0 auto; }
</style>

view raw JSON →