Guides

Import and export

Workspaces, worksheets and single charts as JSON files, and in-page snapshots.

Export

Each export returns { json, blob, filename }. Worksheets and chart settings are included; datasets are not, so a saved workspace re-plots whatever data is loaded when it comes back.

TypeScript
const { json, blob, filename } = engine.io.exportWorkspace()   // every worksheet
engine.io.exportWorksheet(wsId)                                // one worksheet (default: active)
engine.io.exportChart(chartId)                                 // one chart

await fetch('/api/workspaces/42', { method: 'PUT', body: blob })

json is filled for workspaces only; for worksheets and charts read the blob.

Import

TypeScript
// Accepts a File, a Blob, a JSON string or the parsed object.
const { worksheets, errors } = await engine.io.importWorkspace(savedJson)   // replaces all worksheets
const wsId = await engine.io.importWorksheet(file)                          // appended and activated
const chartId = await engine.io.importChart(file, wsId)                     // into a worksheet (default: active)

// One "Open" button for all three:
const parsed = await engine.io.parseFile(file)   // parsed.type: 'workspace' | 'worksheet' | 'chart' | 'error'
if (parsed.type === 'workspace' && engine.io.hasWork() && !(await confirmReplace())) return
  • Chart settings are validated on import; invalid entries fall back to the kind’s defaults.
  • A workspace without worksheets rejects with bad_workspace; a file of the wrong type with bad_file.
  • All of these respect the canImportExportWorkspaces limit.

Snapshots and reset

A snapshot keeps datasets, worksheets and the selection, to rebuild the same state later in the same page (a prepared demo, an undo point). It holds live objects, so it is not serialisable.

TypeScript
const snap = engine.io.snapshot()
// ...
engine.io.restore(snap)
engine.io.reset()   // no datasets, one blank worksheet; live connections stay