json Labs
Convenience module intending to match the standard library json module.
Index
Classes
Error serializing element to SysML v2 JSON. |
||
Class for warnings from serialization and deserialization |
||
Error serializing element to SysML v2 JSON. |
Functions
- dumps(element: syside.Element, options: syside.SerializationOptions, indent: int = 2, use_spaces: bool = True, final_new_line: bool = True, include_cross_ref_uris: bool = True) str[source]
Serialize
elementto a SysML v2 JSONstr.See the documentation of the
SerializationOptionsclass for documentation of the possible options. The options object constructed withSerializationOptions.minimalinstructs to produce a minimal JSON without any redundant elements that results in significantly smaller JSONs. Examples of redundant information that is avoided using minimal configuration are:including fields for null values;
including fields whose values match the default values;
including redefined fields that are duplicates of redefining fields;
including derived fields that can be computed from minimal JSON (for example, the result value of evaluating an expression);
including implied relationships.
Note
SysIDE does not construct all derived properties yet. Therefore, setting
options.include_derivedtoTruemay result in a JSON that does not satisfy the schema.- Parameters:
element – The SysML v2 element to be serialized to SysML v2 JSON.
options – The serialization options to use when serializing SysML v2 to JSON.
indent – How many space or tab characters to use for indenting the JSON.
use_spaces – Whether use spaces or tabs for indentation.
final_new_line – Whether to add a newline character at the end of the generated string.
include_cross_ref_uris – Whether to add potentially relative URIs as
@uriproperty to references of Elements from documents other than the one owningelement. Note that while such references are non-standard, they match the behaviour of XMI exports in Pilot implementation which use relative URIs for references instead of plain element IDs.
- Returns:
elementserialized as JSON.
- loads(s: str, document: syside.Document, attributes: syside.AttributeMap | None = None) syside.DeserializedModel[source]
Deserialize a model from
sinto an already existingdocument.- Parameters:
s – The string contained serialized SysML model in JSON array.
document – The document the model will be deserialized into.
attributes – Attribute mapping of
s. If none provided, this will attempt to infer a corresponding mapping or raise aValueError.
- Returns:
Model deserialized from JSON array. Note that references into other documents will not be resolved, users will need to resolve them by calling
linkon the returned model. See alsoIdMap.
- loads(s: str, document: syside.Url | str, attributes: syside.AttributeMap | None = None) tuple[syside.DeserializedModel, syside.SharedMutex[syside.Document]][source]
Create a new
documentand deserialize a model fromsinto it.- Parameters:
s – The string contained serialized SysML model in JSON array.
document – A URI in the form of
Urlor a string, new document will be created with. If URI path has no extension, or the extension does not matchsysmlorkerml,ValueErroris raised.attributes – Attribute mapping of
s. If none provided, this will attempt to infer a corresponding mapping or raise aValueError.
- Returns:
Model deserialized from JSON array and the newly created document. Note that references into other documents will not be resolved, users will need to resolve them by calling
linkon the returned model. See alsoIdMap.