Vue JSON Compare Component
vue-json-compare is a Vue 2.x component designed for visually comparing two JSON objects or arrays. It accepts `oldData` and `newData` props, highlighting structural and value differences in a side-by-side, hierarchical display. The current stable version, 3.0.0, was last published over 5 years ago and is exclusively compatible with Vue 2 applications. Given that Vue 2 officially reached its end-of-life on December 31, 2023, this package is effectively deprecated and unsupported for new projects. Its primary differentiator was providing an immediate UI solution for JSON diffing within Vue 2 ecosystems, contrasting with lower-level JavaScript diffing libraries by offering a complete visual component. The project appears to be abandoned, with no active development or known support for Vue 3.
Common errors
-
Failed to mount component: template or render function not defined.
cause The Vue component was not correctly imported or registered in the parent component or globally.fixEnsure `import vueJsonCompare from 'vue-json-compare';` is used and `vueJsonCompare` is included in the `components` option of your Vue component. -
Cannot read properties of undefined (reading 'someProperty') in vue-json-compare component
cause The `oldData` or `newData` props were passed as `undefined` or `null`, or contained unexpected non-object/array values where the component expected them.fixAlways ensure `oldData` and `newData` props are valid JavaScript objects or arrays, even if empty, e.g., `:oldData="oldData || {}"` or `:newData="newData || []"`.
Warnings
- breaking This package is explicitly built for Vue 2.x and is not compatible with Vue 3. Attempting to use it in a Vue 3 project will result in runtime errors due to breaking API changes between Vue major versions.
- deprecated The project appears to be abandoned. The last npm publish was over 5 years ago, and the last commit on GitHub was 6 years ago. There is no active development, maintenance, or support for this component. Vue 2 itself reached End of Life on December 31, 2023.
- gotcha The component does not expose any events, meaning there's no programmatic way to interact with user actions within the comparison UI or to get callbacks on changes, as stated in its README.
- gotcha Performance might degrade significantly when comparing very large or deeply nested JSON objects due to client-side DOM rendering and diffing calculations, potentially leading to UI freezes.
Install
-
npm install vue-json-compare -
yarn add vue-json-compare -
pnpm add vue-json-compare
Imports
- vueJsonCompare
import { vueJsonCompare } from 'vue-json-compare';import vueJsonCompare from 'vue-json-compare';
- vueJsonCompare
const vueJsonCompare = require('vue-json-compare');Vue.component('vue-json-compare', vueJsonCompare); - VueJsonCompare
import { VueJsonCompare } from 'vue-json-compare';import type VueJsonCompare from 'vue-json-compare';
Quickstart
<template>
<div>
<vue-json-compare :oldData="oldData" :newData="newData"></vue-json-compare>
</div>
</template>
<script>
import vueJsonCompare from 'vue-json-compare';
export default {
components: {
vueJsonCompare
},
data () {
return {
oldData: {
id: 1,
name: 'Alice',
settings: { theme: 'dark', notifications: true },
tags: ['user', 'admin']
},
newData: {
id: 1,
name: 'Alicia',
age: 30,
settings: { theme: 'light', notifications: true },
tags: ['user', 'premium']
}
};
}
};
</script>