# solid-example-save-json

> Save and load documents as JSON format.

A shadcn/ui block from the [@prosekit](https://prosekit.dev) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/prosekit/solid-example-save-json).

- Page, with a live preview: https://shadcn.exchange/r/prosekit/solid-example-save-json
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/prosekit/solid-example-save-json-light-4223c4625d2f0424.png
- Registry item: https://prosekit.dev/r/solid-example-save-json.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://prosekit.dev/r/solid-example-save-json.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `prosekit`

## Files

### `registry/src/solid/examples/save-json/editor.tsx`

```tsx
import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'

import { defineBasicExtension } from 'prosekit/basic'
import { createEditor, type NodeJSON } from 'prosekit/core'
import { ProseKit, useDocChange } from 'prosekit/solid'
import { createSignal, For, type JSX } from 'solid-js'

export default function Editor(): JSX.Element {
  const [records, setRecords] = createSignal<string[]>([])
  const [hasUnsavedChange, setHasUnsavedChange] = createSignal(false)

  const extension = defineBasicExtension()
  const editor = createEditor({ extension })

  const handleDocChange = () => setHasUnsavedChange(true)
  useDocChange(handleDocChange, { editor })

  const handleSave = () => {
    const record = JSON.stringify(editor.getDocJSON())
    setRecords((prev) => [...prev, record])
    setHasUnsavedChange(false)
  }

  const handleLoad = (record: string) => {
    editor.setContent(JSON.parse(record) as NodeJSON)
    setHasUnsavedChange(false)
  }

  return (
    <div class="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-[canvas] text-black dark:text-white">
      <button
        onClick={handleSave}
        disabled={!hasUnsavedChange()}
        class="m-1 border border-solid bg-white px-2 py-1 text-sm text-black disabled:cursor-not-allowed disabled:text-gray-500"
      >
        {hasUnsavedChange() ? 'Save' : 'No changes to save'}
      </button>
      <ul class="border-b border-t border-solid text-sm">
        <For each={records()}>
          {(record) => (
            <li class="m-1 flex gap-2">
              <button
                class="border border-solid bg-white px-2 py-1 text-black"
                onClick={() => handleLoad(record)}
              >
                Load
              </button>
              <span class="flex-1 overflow-x-scroll p-2">
                <pre>{record}</pre>
              </span>
            </li>
          )}
        </For>
      </ul>
      <ProseKit editor={editor}>
        <div class="relative w-full flex-1 box-border overflow-y-auto">
          <div ref={editor.mount} class="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
        </div>
      </ProseKit>
    </div>
  )
}
```

### `registry/src/solid/examples/save-json/index.ts`

```ts
export { default as ExampleEditor } from './editor.tsx'
```
