toJson method

String toJson([
  1. String? classname
])

Generate a string representation of the persistent data in this model, in JSON format, that can be read in later with a call to Model.fromJson.

Object properties that are not enumerable or whose names start with "_" are not written out.

Functions are not able to be written in JSON format, so any properties that have function values will not be saved in the JSON string.

There must not be any circular references within the model data. Any sharing of object references will be lost in the written JSON.

Most object classes cannot be serialized into JSON without special knowledge and processing at both ends. The #toJson and Model.fromJson methods automatically do such processing for numbers that are NaN and for objects that are of class Point, Size, Rect, Margin, Spot, Brush (but not for brush patterns), and for Geometry. For instances of those classes, special objects are written out with a property named "class" whose value will be one of the special cases that will be substituted by Model.fromJson: "NaN", "Date", "go.EnumValue", "go.Point", "go.Size", "go.Rect", "go.Margin", "go.Spot", "go.Brush", "go.Geometry".

However, we recommend that you use Binding converters (static functions named "parse" and "stringify") to represent Points, Sizes, Rects, Margins, Spots, and Geometries as string values in your data, rather than as Objects. This makes the JSON text smaller and simpler and easier to read.

As a special case when serializing an object, if the property is named "points" and the property value is a List of Points, it will write an Array of numbers.

Note that this is a method on the Model class. It cannot render unmodeled Parts such as the background grid or any Parts that you have added directly to a Diagram.

Typical usage:

var modelAsText = myDiagram.model.toJson();
// now save this text string by sending it to your database

@param {string=} classname The optional name of the model class to use in the output; for the standard models, this is their class name prefixed with "go.". @return {string} a String in JSON format containing all of the persistent properties of the model.

Implementation

_i2.String toJson([_i2.String? classname]) => _i4.callMethod(
      this,
      'toJson',
      [classname ?? _i5.undefined],
    );