Skip to main content

to_json_ld

Function to_json_ld 

Source
pub fn to_json_ld(
    model: &DataModel,
    root: Option<&str>,
) -> Result<JsonLdHeader, Box<dyn Error>>
Expand description

Generate a full JSON-LD document header for the given data model.

This function constructs a JsonLdHeader for a DataModel, using its prefix, object name, and any configured context prefixes. It builds the @context, @id, and @type fields required for compliant JSON-LD output. An explicit root object can be chosen by its name; otherwise, the first object in the model is used.

§Arguments

  • model - Reference to the source DataModel.
  • root - Optional name of the root object; if None, the model’s first object is used.

§Returns

  • Ok(JsonLdHeader) containing complete JSON-LD metadata for the root object.
  • Err(Box<dyn Error>) if the root cannot be found or context creation fails.

§Example

let header = to_json_ld(&model, Some("EnzymeMLDocument")).unwrap();