json Labs
Convenience module intending to match the standard library json module.
Index
Classes
Error deserializing document from SysML v2 JSON. |
||
Error deserializing project from SysML v2 JSON. |
||
Class for exceptions from serialization and deserialization |
||
Class for warnings from serialization and deserialization |
||
Error serializing element to SysML v2 JSON. |
Attributes
Attributes
- type DeserializationReport = syside.SerdeReport[syside.Element | str | syside.DocumentSegment]
- type JsonSourceInto = tuple[syside.Document, str]
- type JsonSourceNew = tuple[str | syside.Url, str]
Used in
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.Root node will be inferred as:
The first
Namespace(not subtype) without an owning relationship.The first
Elementthat has no serialized owning related element or owning relationship, starting from the first element in the JSON array, and following owning elements up.The first element in the array otherwise.
- 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.Root node will be inferred as:
The first
Namespace(not subtype) without an owning relationship.The first
Elementthat has no serialized owning related element or owning relationship, starting from the first element in the JSON array, and following owning elements up.The first element in the array otherwise.
- 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.
- loads(s: Iterable[syside.json.JsonSourceNew | syside.json.JsonSourceInto], /, environment: syside.Environment | None = None, resolve: Callable[[str, uuid.UUID], syside.Element | None] | None = None, attributes: syside.AttributeMap | None = None) tuple[syside.BaseModel, list[tuple[syside.DeserializedModel, syside.json.DeserializationReport]]][source]
Deserialize a project of multiple documents from
s.This is effectively calling
loads(src, document, attributes) for document, src in sand performing the link step afterwards. See also other overloads ofloads.- Parameters:
s – Projects sources to deserialize from. If providing a URL string or a
Url, new documents will be created for corresponding sources, otherwise deserialization will be performed into the providedDocuments.environment –
Environmentthis project depends on. Defaults to the bundled standard library. Theenvironmentwill be used to attempt to resolve missing references in the deserialized project.resolve – User-provided reference resolution callback that takes priority over
environment. SeeDeserializedModel.linkfor more details.attributes – Attribute mapping of
s. If none provided, this will attempt to infer a corresponding mapping or raise aValueError.
- Returns:
A tuple of project deserialized from JSON sources, and deserialization results
- Raises:
ProjectDeserializationError – If either the deserialization or the reference resolution had errors.