Vue JSONEditor Component
v-jsoneditor is a Vue.js wrapper component for the popular `jsoneditor` library, providing a powerful and customizable JSON editor interface within Vue applications. It allows users to view, edit, format, and validate JSON data through a user-friendly GUI or code editor. The current stable version is 1.4.5, with the last update in September 2021. Due to the lack of recent activity, the project appears to be unmaintained, potentially limiting its compatibility with newer Vue versions (e.g., Vue 3) or the latest features and security patches of the underlying `jsoneditor` library. Its primary differentiator is its straightforward integration into Vue 2 projects.
Common errors
-
Failed to resolve component: v-jsoneditor
cause The `v-jsoneditor` component was not properly registered with Vue.fixEnsure you have either called `Vue.use(VJsoneditor)` for global registration or included `VJsoneditor` in the `components` option of the parent component where it's being used. -
TypeError: Cannot read properties of undefined (reading 'install')
cause Attempting to use `Vue.use()` with a module that doesn't provide an `install` method, often due to incorrect import (e.g., `require`ing an ESM-only default export).fixVerify that `VJsoneditor` is correctly imported as a default export: `import VJsoneditor from 'v-jsoneditor';` before passing it to `Vue.use()`. -
[Vue warn]: Avoid using non-primitive value as key, use string/number value instead.
cause While not directly from `v-jsoneditor`, this warning can appear if you are binding an object or array directly as a `key` prop in a `v-for` loop that includes `v-jsoneditor` or another component.fixEnsure all `key` props in `v-for` loops are bound to unique primitive values (strings or numbers), typically an `id` property from your data item.
Warnings
- breaking This package is built for Vue 2.x. It is not directly compatible with Vue 3 without a compatibility layer or significant refactoring, as Vue 3 introduced breaking changes to its API and component registration.
- gotcha The project appears to be abandoned, with the last commit in September 2021. This means it may not receive updates for bug fixes, new features, or compatibility with newer versions of Vue or the underlying `jsoneditor` library. Security vulnerabilities in `jsoneditor` itself might not be patched in this wrapper.
- gotcha The `options` prop directly maps to the `jsoneditor` library's configuration. Ensure you consult the `jsoneditor` documentation for detailed information on available options and their behavior, as this wrapper primarily exposes that API.
- deprecated The underlying `jsoneditor` library has likely evolved since `v-jsoneditor`'s last update. Features or options available in newer `jsoneditor` versions might not be exposed or function correctly with this older wrapper.
Install
-
npm install v-jsoneditor -
yarn add v-jsoneditor -
pnpm add v-jsoneditor
Imports
- VJsoneditor
import { VJsoneditor } from 'v-jsoneditor'import VJsoneditor from 'v-jsoneditor'
- Global Vue plugin
const VJsoneditor = require('v-jsoneditor')import Vue from 'vue' import VJsoneditor from 'v-jsoneditor' Vue.use(VJsoneditor)
- Component options
export default { components: { VJsoneditor }, // ... }
Quickstart
import Vue from 'vue';
import VJsoneditor from 'v-jsoneditor';
Vue.use(VJsoneditor);
new Vue({
el: '#app',
data() {
return {
jsonData: {
message: 'Hello V-JSONEditor!',
version: '1.0.0',
isActive: true,
items: [
{ id: 1, name: 'Item A' },
{ id: 2, name: 'Item B' }
]
},
editorOptions: {
mode: 'code',
modes: ['code', 'tree', 'form', 'view', 'text'],
onError: (err) => {
console.error('JSONEditor error:', err);
}
}
};
},
methods: {
handleError(err) {
console.error('v-jsoneditor component error:', err);
}
},
template: `
<div>
<h1>Vue JSON Editor Demo</h1>
<v-jsoneditor
v-model="jsonData"
:options="editorOptions"
:plus="true"
height="400px"
@error="handleError"
/>
<p>Current JSON: {{ JSON.stringify(jsonData) }}</p>
</div>
`,
});