IF Commons GitHub

integrations/pure/read-json-ld

A reader of JSON-LD (commons 0019-mizan-integrations FR-020, FR-021): the text of an outside ontology published as JSON-LD, in its expanded or its compacted form, as triples, with what the typed form cannot hold named as findings and never dropped silently. It lives here and not in the kernel, which reads no RDF syntax (0012-ontology FR-007).

It reads the JSON once, with its own small parser that keeps each number's text (JSON-LD tells 1 from 1.0, which JSON.parse does not) and each object's line, then expands it by the JSON-LD 1.1 algorithm for what vocabularies use: an inline @context (an object, an array of them, null, in the document or in a node) with @vocab, @base, @language, terms given as an IRI, a compact IRI or an object (@id, @type as @id, @vocab or a datatype, @language, @container of @set, @list, @language or @index, @reverse, @prefix) and the aliases of keywords; @id, @type, @graph at the top, @included, @value with @type and @language, @set, @list, @reverse, nested node objects (a blank node where there is no @id, genid-N in document order) and numbers and booleans as typed literals. A @list is read as the rdf:first and rdf:rest triples it stands for. Each of these is unsupported, named with its line and not read, where it appears: a remote context (a string, which this layer cannot fetch), @import, a scoped context (on a term or a type), a named graph, @nest, a JSON literal (@type: @json), a container of @graph, @id or @type, and a key that expands to no IRI.

import { readJsonLd } from "./read-json-ld.ts";
const r = readJsonLd('{"@context":{"@vocab":"https://example.org/"},"@id":"https://example.org/a","@type":"B","n":3}');
r.kind === "ok" && r.value.triples.length; // 2

Source: commons/mizan/src/integrations/pure/read-json-ld.ts

1 of 2 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

integrations.readJsonLdfunctionno test imports it
function readJsonLd(text: string, base?: string): Result<Read, readonly IntegrationFinding[]>

JSON-LD text as triples, with the findings of what the typed form cannot hold; JSON that is not well formed, or a context that is not one, ends the read with one syntax finding and its line. base is the IRI the document was read from, which a relative @id resolves against where the context has no @base.

readJsonLdfunction
function readJsonLd(text: string, base?: string): Result<Read, readonly IntegrationFinding[]>

JSON-LD text as triples, with the findings of what the typed form cannot hold; JSON that is not well formed, or a context that is not one, ends the read with one syntax finding and its line. base is the IRI the document was read from, which a relative @id resolves against where the context has no @base.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.