Skip to content

cy.json(flat?)

cy.json — Core > Export and snapshots > Graph data and wire format. Cytoscape.js signatures, parameters and return contract.

cy.json — Core › Export and snapshots › Graph data and wire format

Preview · Core › Export and snapshots › Graph data and wire format

Read in the complete API reference · All API members

// Export a plain-object snapshot containing elements, stylesheet, viewport, interaction settings and graph-level data
cy.json(flat?: boolean): Record<string, unknown>

Export a plain-object snapshot containing elements, stylesheet, viewport, interaction settings and graph-level data.

This method is export-only: json(object) is not supported. Use patch() to reconcile incoming element data, clone() to copy a live instance, or serialize() to save a compact element payload for later loading.

Parameters
NameDescription
flat: boolean?

when true, elements export as one flat array instead of { nodes, edges }

Returns Record<string, unknown>

the exported graph

Example

console.log(cy.json().elements.nodes.length); // 3

Example graph and handle setup

Throws

if given anything but a boolean — the guard that catches an attempted json( obj) import