# HTML and JSON export {#html-and-json}

Source: [Export HTML and JSON from a React editor · Yurich](https://leeyujoo.com/yurich/features/html-and-json/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

Save editable HTML and read structured JSON.

## Try it {#try-it}

Click **Export**. The callback receives `html` containing `<p><strong>Ship it</strong></p>` and a JSON document whose text node carries a `bold` mark. Use `onChange` and `onChangeJSON` to observe updates between saves.

## Add it to your editor {#setup}

Use `getHTML()` when your app needs to save and reopen a document. Use `getJSON()` for a structured representation such as a content preview or indexing.

```tsx
import {
  Bold, EditorContent, EditorProvider, useEditor, type DocumentJSON,
} from 'yurich';

export function ExportEditor({ onSave }: {
  onSave: (draft: { html: string; json: DocumentJSON }) => void;
}) {
  const editor = useEditor({
    extensions: [Bold],
    initialValue: "<p><strong>Ship it</strong></p>",
  });

  return (
    <EditorProvider editor={editor}>
      <EditorContent ariaLabel="Editor" />
      <button type="button" onClick={() => onSave({
        html: editor.getHTML(),
        json: editor.getJSON(),
      })}>
        Export
      </button>
    </EditorProvider>
  );
}
```

## Behavior to account for {#behavior}

Treat JSON results as immutable. The public editor loads HTML, so save the HTML if the document will reopen. See [Save and restore HTML](https://leeyujoo.com/yurich/#save-and-restore-html) for loading a saved draft.

[Features](https://leeyujoo.com/yurich/features/)
