NAME
rdf/jsonld - JSON-LD parser and serializer facade.
SYNOPSIS
from rdf/jsonld import
JsonLdParser,
JsonLdSerializer,
jsonld_expand,
jsonld_compact,
jsonld_flatten,
jsonld_frame,
jsonld_decode_text;
let expanded := jsonld_expand(data, { base: "https://example.test/" });
let compacted := jsonld_compact(expanded, {
"@context": { ex: "https://example.test/" },
});
let flattened := jsonld_flatten(data);
DESCRIPTION
This module re-exports the JSON-LD, YAML-LD, CBOR-LD, and compressed CBOR-LD RDF parser and serializer classes, plus the public JSON-LD API functions implemented by this distribution.
The parser and serializer classes operate on RDF quads and compose the RdfParser and RdfSerializer traits from the main rdf distribution. The JSON-LD API functions operate on decoded JSON-like ZuzuScript data structures.
EXPORTS
Classes
JsonLdParser,YamlLdParser,CborLdParser,CompressedCborLdParserParse JSON-LD, YAML-LD, plain CBOR-LD, or compressed CBOR-LD into RDF quads, or into a supplied RDF store via the
intooption.JsonLdSerializer,YamlLdSerializer,CborLdSerializer,CompressedCborLdSerializerSerialize RDF quads as expanded JSON-LD data encoded as JSON, YAML, or CBOR. The compressed CBOR-LD serializer emits tagged CBOR-LD using registry entry 1 by default.
Functions
jsonld_expand(data, options?)Expands a JSON-LD document into expanded JSON-LD form. Supported options include
base,compact_arrays,expand_context, anddocument_loader.document_loadermay be a function taking a URL or an object withload_document(url); it should return either decoded JSON-LD data or a remote document dictionary withdocument,document_url,content_type, andcontext_urlkeys.jsonld_decode_text(text, options...)Decodes JSON text, or extracts JSON-LD script elements from HTML when
content_typecontainshtmlor the text looks like an HTML document. HTML extraction supportsbasefor fragment targeting andextract_all_scripts.jsonld_compact(data, context, options?)Expands
dataand compacts it usingcontext. The result includes@context.jsonld_flatten(data, context?, options?)Expands and flattens
data. Whencontextis supplied, the flattened result is compacted using that context.jsonld_frame(data, frame, options?)Expands, flattens, frames, and compacts
datausing a JSON-LD frame. The implementation supports graph/type framing with nested node embedding and uses the frame@contextas the output context.jsonld_to_rdf,rdf_to_jsonld_dataLower-level ToRDF and FromRDF helpers used by the parser and serializer classes.
cborld_to_jsonld_data,jsonld_data_to_cborldLower-level helpers for converting between decoded JSON-LD data and tagged CBOR-LD values.
jsonld_object_equalsCompares JSON-LD result objects in tests while ignoring object member ordering.
COPYRIGHT AND LICENCE
rdf/jsonld is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.