# Angular Spreadsheet JSON Import and Export

The Spreadsheet can serialize its entire workbook state, including cell values, formatting, formulas, and sheet configuration, to a plain JavaScript object and restore it at any time. This makes the JSON API ideal for scenarios like auto-saving drafts or persisting state to a database.

## Importing JSON Data

To programmatically load a workbook from a JavaScript object, use the [`fromJSON`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetwidget#fromjson) method of [`SpreadsheetWidget`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetwidget). The object must conform to the [`DocumentDescriptor`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/documentdescriptor) type, which describes the full workbook structure including sheets, rows, cells, and their properties.

```ts
public loadJSON(spreadsheet: SpreadsheetComponent): void {
    spreadsheet.spreadsheetWidget.fromJSON({ sheets: data });
}
```

The following example demonstrates the `fromJSON` method in action.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/import-export/json/import/source.txt)

## Exporting to JSON

To serialize the current workbook state, use either the [`saveJSON`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetwidget#savejson) or [`toJSON`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetwidget#tojson) method of [`SpreadsheetWidget`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetwidget). Both methods return a JavaScript object that captures all sheets, cell values, formatting, and formulas.

The key difference is that `saveJSON` returns a `Promise`, which makes it the correct choice when the workbook contains embedded images that require asynchronous processing. Use `toJSON` for synchronous serialization when no images are present.

```ts
public onSave(spreadsheet: SpreadsheetComponent): void {
    // saveJSON handles embedded images asynchronously.
    spreadsheet.spreadsheetWidget.saveJSON().then((data) => {
        this.jsonData = data;
    });
}
```

The following example demonstrates the `saveJSON` method in action.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/import-export/json/export/source.txt)

## Suggested Links

* [Excel Import & Export](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/import-export/excel)
* [PDF Export](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/import-export/pdf-export)
* [API Reference of the `DocumentDescriptor`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/documentdescriptor)
* [API Reference of the `SpreadsheetComponent`](https://www.telerik.com/kendo-angular-ui-develop/components/spreadsheet/api/spreadsheetcomponent)
