Vue Components

@visual-json/vue provides a complete set of Vue 3 components for building visual JSON editors. All components are designed to work together inside a VisualJson provider.

npm install @visual-json/vue @visual-json/core

Peer dependency: Vue 3.3 or later.

VisualJson

The root provider that manages tree state, selection, expansion, undo/redo, search, and schema. All other components must be rendered inside this provider.

<script setup>
import { VisualJson } from "@visual-json/vue";
</script>

<template>
  <VisualJson :value="json" :schema="schema" @change="onJsonChange">
    <!-- child components -->
  </VisualJson>
</template>
PropTypeDescription
valueJsonValueThe JSON data to edit
schemaJsonSchema | nullOptional JSON Schema for validation and form hints
EventPayloadDescription
changeJsonValueEmitted when the data changes

JsonEditor

Batteries-included component — bundles a tree sidebar, form editor, search bar, and responsive layout.

<script setup>
import { ref } from "vue";
import { JsonEditor } from "@visual-json/vue";

const value = ref({ hello: "world" });
</script>

<template>
  <JsonEditor :value="value" @change="value = $event" />
</template>
PropTypeDescription
valueJsonValueControlled JSON value
defaultValueJsonValueUncontrolled initial value
schemaJsonSchema | nullOptional JSON Schema for validation and hints
readOnlybooleanDisable editing
sidebarOpenbooleanShow/hide tree sidebar
treeShowValuesbooleanDisplay values in tree nodes
treeShowCountsbooleanDisplay child counts in tree nodes
editorShowDescriptionsbooleanShow schema descriptions in the form
editorShowCountsbooleanShow child counts in the form
height / widthstring | numberContainer dimensions
styleRecord<string, string>CSS custom property overrides
EventPayloadDescription
changeJsonValueEmitted when the data changes

TreeView

Hierarchical tree with expand/collapse, drag-and-drop, keyboard navigation, and right-click context menus.

<template>
  <TreeView :show-values="true" :show-counts="false" />
</template>

FormView

Schema-aware form editor. Renders fields with descriptions, required indicators, and enum dropdowns when a schema is provided.

<template>
  <FormView :show-descriptions="true" :show-counts="false" />
</template>

DiffView

Side-by-side comparison of two JSON values with color-coded additions, removals, and changes.

<template>
  <DiffView :original-json="original" :current-json="current" />
</template>
PropTypeDescription
originalJsonunknownThe original JSON value
currentJsonunknownThe current/modified JSON value
classstringOptional CSS class

Breadcrumbs

Displays the path to the currently selected node as clickable breadcrumbs.

<template>
  <Breadcrumbs />
</template>

SearchBar

Search input with next/previous navigation. Supports Cmd/Ctrl+F to focus.

<template>
  <SearchBar />
</template>

ContextMenu

Rendered by TreeView on right-click. Can also be used standalone via <Teleport>.

<template>
  <ContextMenu
    :x="100"
    :y="200"
    :items="[
      { label: 'Copy', action: handleCopy },
      { separator: true },
      { label: 'Delete', action: handleDelete },
    ]"
    @close="handleClose"
  />
</template>

useStudio Composable

Access the full studio state and actions from any component inside VisualJson.

<script setup>
import { useStudio } from "@visual-json/vue";

const { state, actions } = useStudio();
</script>

<template>
  <button :disabled="!state.canUndo.value" @click="actions.undo()">
    Undo
  </button>
</template>

State

FieldTypeDescription
treeRef<TreeState>Current tree state
selectedNodeIdRef<string | null>Currently selected node
expandedNodeIdsRef<Set<string>>Set of expanded node IDs
schemaRef<JsonSchema | null>Active JSON Schema
searchQueryRef<string>Current search query
searchMatchesRef<SearchMatch[]>Search results
searchMatchIndexRef<number>Index of the active match
searchMatchNodeIdsComputedRef<Set<string>>Node IDs with matches
canUndoComputedRef<boolean>Whether undo is available
canRedoComputedRef<boolean>Whether redo is available

Actions

ActionDescription
setTree(state)Replace the tree state
selectNode(id)Select a node
toggleExpand(id)Toggle node expansion
expandNode(id)Expand a node
collapseNode(id)Collapse a node
expandAll()Expand all nodes
collapseAll()Collapse all nodes
undo()Undo last change
redo()Redo last undone change
setSearchQuery(q)Update search query
nextSearchMatch()Jump to next match
prevSearchMatch()Jump to previous match

Theming

All components read CSS custom properties for colors, fonts, and spacing. Override them via the style prop or on a parent element:

<JsonEditor
  :value="data"
  :style="{
    '--vj-bg': '#ffffff',
    '--vj-text': '#111111',
    '--vj-border': '#e5e5e5',
    '--vj-accent': '#2563eb',
    '--vj-font': '\'Fira Code\', monospace',
  }"
  @change="data = $event"
/>