# Экспорт HTML и JSON {#html-and-json}

Source: [Экспорт HTML и JSON из редактора React · Yurich](https://leeyujoo.com/yurich/ru/features/html-and-json/)

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

Package version: `0.1.2`

Сохраняйте редактируемый HTML и читайте структурированный JSON.

## Попробуйте {#try-it}

Нажмите **Экспорт**. Обработчик получит HTML и JSON с меткой `bold` в текстовом узле.

## Добавьте в редактор {#setup}

Используйте `getHTML()` для повторно открываемых документов и `getJSON()` для структурированных данных.

```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>Готово</strong></p>",
  });

  return (
    <EditorProvider editor={editor}>
      <EditorContent ariaLabel="Редактор" />
      <button type="button" onClick={() => onSave({
        html: editor.getHTML(),
        json: editor.getJSON(),
      })}>
        Экспорт
      </button>
    </EditorProvider>
  );
}
```

## Особенности поведения {#behavior}

Относитесь к JSON как к неизменяемому. Для повторного открытия нужен HTML, см. [сохранение и восстановление](https://leeyujoo.com/yurich/ru/#save-and-restore-html).

[Возможности](https://leeyujoo.com/yurich/ru/features/)
