Expansion transforms a JSON-LD document into an expanded form. You can describe the document to be expanded using:
RemoteDocument: Wraps the JSON representation alongside its remote URL.RemoteDocumentReference: Represents only a URL, allowing a loader to fetch the document via dereferencing.
Use the JsonLdProcessor::expand method on the document. If you are using lightweight index types for IRIs, use expand_with instead.
use iref::IriBuf;
use static_iref::iri;
use json_ld::{JsonLdProcessor, Options, RemoteDocument, syntax::{Value, Parse}};
// Create a "remote" document by parsing a file manually.
let input = RemoteDocument::new(
Some(iri!("https://example.com/sample.jsonld").to_owned()),
Some("application/ld+json".parse().unwrap()),
Value::parse_str(r"#{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name"
},
"@id": "https://www.rust-lang.org",
"name": "Rust Programming Language"
}"#).expect("unable to parse file").0
);
let mut loader = json_ld::NoLoader;
let expanded = input
.expand(&mut loader)
.await
.expect("expansion failed");