Serialization & validation
Everything you build in code round-trips to and from OntoUML JSON — the exact format the visual editor reads and writes. That is what makes the library interoperable: a model authored in a script can be opened on a canvas, and a diagram drawn by hand can be loaded, queried, and transformed in code.
OntoUML JSON is specified by a public JSON Schema published at
https://w3id.org/ontouml/schema. A project
serializes to a single object with a type: "Project" discriminator, its
metadata, and a flat elements array — every class, relation, property,
generalization, package, diagram, and view, each tagged with its own type.
References between elements (a relation's ends, a generalization's general and
specific, a package's contents) are stored by id, and the parser resolves
them back into live object references when it reads the file.
Serializing
Every element implements toJSON(), so plain JSON.stringify already produces
schema-conformant output. Prefer serializationUtils.serialize, which does the
same but validates the result against the schema before returning it —
failing fast if the model ever produces a non-conformant serialization. Pass a
spacing argument for a human-readable file.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project, const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const project: Projectproject.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.add(value: string, language?: string): voidAdds a text value in the given language, replacing any existing value for
that language.add('School enrollment');
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Model').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const const person: Classperson = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const school: Classschool = const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('School').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const model: Packagemodel
.Package.binaryRelationBuilder(): BinaryRelationBuilderCreates a builder for a
BinaryRelation
contained in this
package.binaryRelationBuilder()
.BinaryRelationBuilder.material(): BinaryRelationBuilderSets the stereotype of the relation to «material», which decorates
relations between endurants that are founded on relators, such as being
married to or being enrolled at. Also applies the following defaults:
- `isDerived = true`material()
.NamedElementBuilder<BinaryRelationBuilder>.name(value: string, language?: string): BinaryRelationBuilderAdds a name to the element in the given language.name('studies at')
.BinaryRelationBuilder.source(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the source end of the relation.source(const person: Classperson)
.BinaryRelationBuilder.target(classifier: Classifier<any, any>): BinaryRelationBuilderSets the
Classifier
connected to the target end of the relation.target(const school: Classschool)
.BinaryRelationBuilder.build(): BinaryRelationBuilds an instance of
BinaryRelation
with the parameters passed
to the builder. Both the source and the target classifiers are required
before `build()` is evoked. **WARNING:** the ordering in which methods
are evoked may affect the resulting object. When no methods are evoked,
the created relation has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`build();
// Compact — for storage or transport. Validated against the schema.
const const json: stringjson = const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.serialize: (project: Project, space?: string | number) => stringSerializes a
Project
into a JSON string conformant to the OntoUML
JSON Schema (https://w3id.org/ontouml/schema), validating the result
against the schema before returning it.serialize(const project: Projectproject);
// Pretty-printed — for a file a human will read.
const const pretty: stringpretty = const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.serialize: (project: Project, space?: string | number) => stringSerializes a
Project
into a JSON string conformant to the OntoUML
JSON Schema (https://w3id.org/ontouml/schema), validating the result
against the schema before returning it.serialize(const project: Projectproject, 2);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const json: stringjson.String.slice(start?: number, end?: number): stringReturns a section of a string.slice(0, 24)); // {"type":"Project","id":…
Write pretty to a .ontouml file (or any .json) and it will open in the
visual tools; the top-level type: "Project" is what identifies it.
Deserializing
To go the other way, hand the JSON string to serializationUtils.parse. It
rebuilds a live Project — with real object references, not ids — so the query
and navigation methods work immediately on the result.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project, const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Model').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const json: stringjson = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.stringify(const project: Projectproject);
// …later, or in another program:
const const restored: Projectrestored = const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.parse: (serializedProject: string) => ProjectParses a
Project
serialized into a string, as defined by the
OntoUML JSON Schema (https://w3id.org/ontouml/schema), and returns the
corresponding instance of
Project
. The input is validated against
the schema before any element is deserialized.
Model elements, diagrams, views, and shapes are fully supported. When the
shapes referenced by a view are absent from the serialization, the view
keeps the serialized shape identifiers but its shapes are recreated with
default dimensions and positions.parse(const json: stringjson);
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const restored: Projectrestored instanceof class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project); // true
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const restored: Projectrestored.Project.classes: Class[]The classes contained in this project.classes.Array<Class>.map<string>(callbackfn: (value: Class, index: number, array: Class[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.map(c: Classc => c: Classc.NamedElement.getNameOrId(language?: string): stringReturns the name of this element in the given language, falling back to
its
id
when no suitable name is available.getNameOrId())); // [ "Person" ]
parse throws a descriptive error rather than returning a broken model when the
input is not a serialized project, when it violates the JSON Schema, or when a
reference cannot be resolved — for example, a relation whose end points at an id
that is absent from elements. The schema check runs before any element is
deserialized, so malformed input from an external source fails fast with a list
of violations instead of surfacing as a confusing error halfway through parsing.
Model elements, diagrams, views, and shapes (the concrete rectangles and
paths carrying pixel geometry) are all serialized as project elements and
fully preserved by parse. When a serialization omits the shapes referenced
by its views, the parsed views keep the shape ids but get default positions
and sizes. See Diagrams for details.
Round-trip fidelity
Parsing a serialization and serializing it again yields byte-identical JSON: the parser registers elements in the order they appear in the file on purpose. That property is what lets you treat OntoUML JSON as a stable interchange format — a model edited in code and one edited on the canvas diff cleanly.
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project, const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const project: Projectproject.NamedElement.name: LanguageStringThe name of this element, possibly in multiple languages.name.LanguageString.add(value: string, language?: string): voidAdds a text value in the given language, replacing any existing value for
that language.add('Roundtrip');
const const model: Packagemodel = const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Model').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
const model: Packagemodel.Package.classBuilder(): ClassBuilderCreates a builder for a
Class
contained in this package.classBuilder().ClassBuilder.kind(): ClassBuilderSets the stereotype of the class to «kind», which decorates rigid
classes that provide an identity principle to their instances, which are
functional complexes (e.g., `Person`, `Car`). Also applies the following
defaults:
- `restrictedTo = [ "functional-complex" ]`
- `order = 1`kind().NamedElementBuilder<ClassBuilder>.name(value: string, language?: string): ClassBuilderAdds a name to the element in the given language.name('Person').ClassBuilder.build(): ClassBuilds an instance of
Class
with the parameters passed to the
builder. **WARNING:** the ordering in which methods are evoked may
affect the resulting object. When no methods are evoked, the created
class has the following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `isAbstract: false,`
- `isDerived: false,`
- `order: 1,`
- `isPowertype: false,`build();
const const first: stringfirst = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.stringify(const project: Projectproject);
const const second: stringsecond = var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.stringify(const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.parse: (serializedProject: string) => ProjectParses a
Project
serialized into a string, as defined by the
OntoUML JSON Schema (https://w3id.org/ontouml/schema), and returns the
corresponding instance of
Project
. The input is validated against
the schema before any element is deserialized.
Model elements, diagrams, views, and shapes are fully supported. When the
shapes referenced by a view are absent from the serialization, the view
keeps the serialized shape identifiers but its shapes are recreated with
default dimensions and positions.parse(const first: stringfirst));
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log(const first: stringfirst === const second: stringsecond); // true
Validating against the schema
Both serialize and parse validate automatically, so most code never calls
the validator by hand. When you want the check on its own — say, to vet a file
before deciding what to do with it — use serializationUtils.validate. It
accepts either a JSON string or an already-parsed object, returns silently on
success, and throws an error listing every schema violation:
import { class ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project, const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils } from 'ontouml-js';
const const project: Projectproject = new new Project(): ProjectAn OntoUML project: the top-level container of an ontology and the entry
point of this library. A project holds every element of a model — classes,
relations, generalizations, packages, properties, notes — as well as the
diagrams and views that depict them, and provides typed access to these
elements by id or by kind.
New elements are created through the fluent builders exposed by the
project (e.g.,
classBuilder
,
binaryRelationBuilder
), which
register the created elements in the project.
A project is also described by the metadata fields of the OntoUML/UFO
Catalog Metadata Vocabulary, such as publisher, license, keywords, themes,
and designed-for tasks.Project();
const project: Projectproject.Project.packageBuilder(): PackageBuilderCreates a builder for a new
Package
in this project.packageBuilder().PackageBuilder.root(): PackageBuilderSets the package as the root package of its project, i.e., the package
that contains the entire model.root().NamedElementBuilder<PackageBuilder>.name(value: string, language?: string): PackageBuilderAdds a name to the element in the given language.name('Model').PackageBuilder.build(): PackageBuilds an instance of
Package
with the parameters passed to the
builder. When no methods are evoked, the created package has the
following defaults:
- `id: "randomly-generated-id",`
- `created: new Date(),`
- `contents: []`build();
// Passes silently: the library produces valid OntoUML JSON.
const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.validate: (serializedProject: object | string) => voidValidates a serialized
Project
against the OntoUML JSON Schema
(https://w3id.org/ontouml/schema).validate(var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.stringify(const project: Projectproject));
// Throws, listing the violations found by the schema.
try {
const serializationUtils: {
parse: (serializedProject: string) => Project;
serialize: (project: Project, space?: string | number) => string;
validate: (serializedProject: object | string) => void;
}
A utility module supporting the serialization, deserialization, and
validation of
Project
objects according to the OntoUML JSON Schema
(https://w3id.org/ontouml/schema). Both
serialize
and
parse
validate the serialization against the schema, throwing on invalid input.serializationUtils.validate: (serializedProject: object | string) => voidValidates a serialized
Project
against the OntoUML JSON Schema
(https://w3id.org/ontouml/schema).validate('{ "type": "Project" }');
} catch (var e: anye) {
var console: Consoleconsole.Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)log((var e: anye as Error).Error.message: stringmessage.String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)Split a string into substrings using the specified separator and return them as an array.split(':')[0]);
// Invalid serialization according to the OntoUML JSON Schema
}
Under the hood, the library ships the schema (published as the
ontouml-schema npm package and
at https://w3id.org/ontouml/schema) and
compiles it with Ajv on first use. If you need to
validate in another stack, the schema targets JSON Schema draft 2020-12 and
uses string formats, so any compliant validator works.
Schema validation only checks structure — that ids resolve, types are known, cardinalities are well-formed. It does not check whether the model is ontologically sound (a role with no identity provider, a mediation on a non-relator). Those are OntoUML anti-patterns; the query methods in Querying give you the raw material to write such checks yourself.
Now you try it
The editor below builds a two-class model, serializes it, parses it back, and
should report true for a clean round-trip. Add a third class of your own and
confirm it survives the trip.
Key takeaways
- Serialize with
serializationUtils.serialize(project)— the output is validated against the OntoUML JSON Schema before it is returned. (JSON.stringify(project)produces the same JSON, without the check.) - Deserialize with
serializationUtils.parse(json), which validates the input against the schema, then rebuilds a liveProjectand resolves all references — throwing on broken input at either step. - The round-trip is byte-identical, making OntoUML JSON a stable interchange format between code and the visual editor.
- Shapes are serialized along with views, so diagram geometry round-trips.
- Use
serializationUtils.validate(input)to run the schema check on its own; structural validity is not ontological validity.
That closes the tour. From here, revisit Querying to turn models into analyses, or the visual editor to see what you built on a canvas.