Serialization

JSON

belso.serialization.json_format.to_json(schema, file_path=None, schema_name='')[source]

Serialize schema in JSON format.

Args

  • schema (Type[Schema]): schema to serialize.

  • file_path (Optional[Union[str, Path]], optional): path to save the JSON file.

  • schema_name (str, optional): prefix to apply to the root schema name.

Returns

  • Dict[str, Any]: dict JSON-ready representation of schema.

belso.serialization.json_format.from_json(json_input, schema_name='')[source]

Load JSON (string / file / dict) into a belso Schema.

Args

  • json_input (Union[str, Path, Dict[str, Any]]): JSON input to load.

  • schema_name (str, optional): prefix to apply to the root schema name.

Returns

  • Type[Schema]: belso Schema loaded from JSON input.

YAML

belso.serialization.yaml_format.to_yaml(schema, file_path=None, schema_name='')[source]

Serialise schema to YAML. schema_name is applied once to the root schema only; children keep their own names untouched.

Args

  • schema (Type[Schema]): schema to serialise.

  • file_path (Optional[Union[str, Path]]): path to save the YAML file.

  • schema_name (str): prefix to apply to the root schema name.

Returns

  • str: YAML representation of schema.

belso.serialization.yaml_format.from_yaml(yaml_input, schema_name='')[source]

Load YAML (string / file / dict) into a belso Schema. schema_name is applied only to the root schema name.

Args

  • yaml_input (Union[str, Path, Dict[str, Any]]): YAML input.

  • schema_name (str): prefix to apply to the root schema name.

Returns

  • Type[Schema]: schema deserialised from yaml_input.

XML

belso.serialization.xml_format.to_xml(schema, file_path=None, schema_name='')[source]

Serialise schema to XML. schema_name is applied once to the root schema only; children keep their own names untouched.

Args

  • schema (Type[Schema]): schema to serialise.

  • file_path (Optional[Union[str, Path]]): path to save the XML file.

  • schema_name (str): prefix to apply to the root schema name.

Returns

  • str: XML representation of schema.

belso.serialization.xml_format.from_xml(xml_input, schema_name='')[source]

Load XML (string / file / Element) into a belso Schema. schema_name is applied only to the root schema name.

Args

  • xml_input (Union[str, Path, ET.Element]): XML input.

  • schema_name (str): prefix to apply to the root schema name.

Returns

  • Type[Schema]: schema deserialised from xml_input.