# Exportação HTML e JSON {#html-and-json}

Source: [Exporte HTML e JSON do editor React · Yurich](https://leeyujoo.com/yurich/pt-br/features/html-and-json/)

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

Package version: `0.1.2`

Salve HTML editável e leia JSON estruturado.

## Experimente {#try-it}

Clique em **Exportar**. O callback recebe HTML e um nó de texto com a marca `bold` no JSON.

## Adicione ao seu editor {#setup}

Use `getHTML()` para gravar um documento reabrível e `getJSON()` para obter dados estruturados.

```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>Pode publicar</strong></p>",
  });

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

## Como o recurso se comporta {#behavior}

Trate o JSON como imutável. O carregamento usa HTML, como em [Salvar e restaurar HTML](https://leeyujoo.com/yurich/pt-br/#save-and-restore-html).

[Recursos](https://leeyujoo.com/yurich/pt-br/features/)
