Python API reference

The supported library interface consists of two decoding functions and one graph-writing utility. The signatures, defaults, parameter descriptions, and raised exceptions below are rendered from the live public functions and their docstrings. See Python library guide for task-oriented guidance.

json2graph.library.decode_json_project(json_file_path, base_uri=None, language='', correct=False, invalid_stereotype_policy='preserve', invalid_cardinality_policy='preserve', unresolved_model_element_policy='omit', transformation_metadata='none', append_content_hash=False, path_order_policy='warn', property_assignment_policy='warn')

Decode an OntoUML JSON project, including supported diagrammatic data.

The returned RDFLib graph contains the project, domain-level model, and supported diagrammatic resources. The decoder expects the OntoUML JSON structure but does not perform JSON Schema validation.

Parameters:
  • json_file_path (str) – Path to the OntoUML JSON file.

  • base_uri (str or None) – Explicit absolute base URI for generated resources. When omitted, a deterministic urn:uuid: base is derived from the parsed JSON document.

  • language (str) – Language tag applied to source name literals. An empty string leaves names without a language tag.

  • correct (bool) – Enable the legacy class and property correction pass. This is independent of the explicit policy parameters.

  • invalid_stereotype_policy (str) – Handle stereotypes invalid for their element type with preserve, omit, or error. Default is preserve.

  • invalid_cardinality_policy (str) – Handle invalid cardinalities with preserve, limited safe repair, or error. Default is preserve.

  • unresolved_model_element_policy (str) – Handle unresolved diagrammatic modelElement references with preserve, omit, or error. Default is omit.

  • transformation_metadata (str) – Return no provenance with none or add it to the graph with embedded. Sidecar output is not available through the library.

  • append_content_hash (bool) – Append the deterministic content UUID below a supplied base_uri.

  • path_order_policy (str) – Handle path-point order with warn or add a non-normative rdfs:comment with comment. Default is warn.

  • property_assignment_policy (str) – Handle non-empty propertyAssignments with warn or preserve canonical JSON in a non-normative comment with comment. Default is warn.

Returns:

Decoded RDF graph.

Return type:

Graph

Raises:
  • ValueError – If an option is invalid or an error policy rejects source content.

  • OSError – If the input file cannot be read.

json2graph.library.decode_json_model(json_file_path, base_uri=None, language='', correct=False, invalid_stereotype_policy='preserve', invalid_cardinality_policy='preserve', unresolved_model_element_policy='omit', transformation_metadata='none', append_content_hash=False, path_order_policy='warn', property_assignment_policy='warn')

Decode the domain-level model from an OntoUML JSON project.

The returned RDFLib graph excludes project and diagrammatic resources while retaining model elements, including enumeration literals. The decoder expects the OntoUML JSON structure but does not perform JSON Schema validation.

Parameters:
  • json_file_path (str) – Path to the OntoUML JSON file.

  • base_uri (str or None) – Explicit absolute base URI for generated resources. When omitted, a deterministic urn:uuid: base is derived from the parsed JSON document.

  • language (str) – Language tag applied to source name literals. An empty string leaves names without a language tag.

  • correct (bool) – Enable the legacy class and property correction pass. This is independent of the explicit policy parameters.

  • invalid_stereotype_policy (str) – Handle stereotypes invalid for their element type with preserve, omit, or error. Default is preserve.

  • invalid_cardinality_policy (str) – Handle invalid cardinalities with preserve, limited safe repair, or error. Default is preserve.

  • unresolved_model_element_policy (str) – Handle unresolved diagrammatic modelElement references with preserve, omit, or error. Default is omit.

  • transformation_metadata (str) – Return no provenance with none or add it to the graph with embedded. Sidecar output is not available through the library.

  • append_content_hash (bool) – Append the deterministic content UUID below a supplied base_uri.

  • path_order_policy (str) – Accepted for parity with project decoding. Model-only output contains no paths, so this option does not change the graph.

  • property_assignment_policy (str) – Handle non-empty propertyAssignments on retained model elements with warn or comment. Default is warn.

Returns:

Decoded model-only RDF graph.

Return type:

Graph

Raises:
  • ValueError – If an option is invalid or an error policy rejects source content.

  • OSError – If the input file cannot be read.

json2graph.library.save_graph_file(ontouml_graph, output_file_path, syntax)

Serialize an RDFLib graph to the requested file.

Accepted syntax names are turtle, ttl, turtle2, xml, pretty-xml, json-ld, ntriples, nt, nt11, n3, trig, trix, and nquads.

Parameters:
  • ontouml_graph (Graph) – Graph to serialize.

  • output_file_path (str) – Complete destination path, including filename and extension.

  • syntax (str) – Supported RDFLib serialization name.

Raises:
  • ValueError – If syntax is not supported.

  • OSError – If the output file cannot be written.

Return type:

None