JSPM

@visual-json/core

0.4.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 32886
    • Score
      100M100P100Q148611F
    • License Apache-2.0

    Headless core for visual-json — the visual JSON editor. Schema-aware, embeddable, extensible.

    Package Exports

    • @visual-json/core

    Readme

    @visual-json/core

    Headless core for visual-json — the visual JSON editor. Schema-aware, embeddable, extensible.

    This package is framework-agnostic — it provides the data layer without any UI dependencies.

    Install

    npm install @visual-json/core

    Usage

    import { fromJson, toJson, setValue, addProperty } from "@visual-json/core";
    
    // Convert a JSON value into an editable tree
    const tree = fromJson({ name: "my-app", version: "1.0.0" });
    
    // Mutate immutably — returns a new tree with structural sharing
    const updated = setValue(tree, tree.root.children[0].id, "new-app");
    
    // Convert back to plain JSON
    const json = toJson(updated.root);

    API

    Tree

    Export Description
    fromJson(value) Parse a JsonValue into a TreeState
    toJson(node) Serialize a TreeNode back to a JsonValue
    findNode(state, id) Look up a node by ID
    findNodeByPath(state, path) Look up a node by JSON path

    Operations

    All operations return a new TreeState with structural sharing.

    Export Description
    setValue(state, nodeId, value) Set a node's value
    setKey(state, nodeId, newKey) Rename an object key
    addProperty(state, parentId, key, value) Add a child to an object or array
    insertProperty(state, parentId, key, value, index) Insert a child at a specific index
    insertNode(state, parentId, node, index) Insert an existing node subtree at a specific index, preserving IDs
    removeNode(state, nodeId) Remove a node
    moveNode(state, nodeId, newParentId, index?) Move a node to a new parent
    reorderChildren(state, parentId, from, to) Reorder children within a parent
    reorderChildrenMulti(state, parentId, movedIds, targetSiblingId, position) Reorder multiple children relative to a sibling
    changeType(state, nodeId, newType) Convert a node to a different type
    duplicateNode(state, nodeId) Duplicate a node as a sibling

    Schema

    Export Description
    resolveSchema(value, filename) Auto-detect and fetch a JSON Schema for a file
    getPropertySchema(schema, path) Get the schema for a specific path
    validateNode(node, schema) Validate a node against a schema

    Search & Diff

    Export Description
    searchNodes(state, query) Full-text search across keys and values
    computeDiff(a, b) Compute a structural diff between two JSON values
    History Undo/redo stack for TreeState

    License

    Apache-2.0