Home

Awesome

[!IMPORTANT] Please consider a donation to keep the project available and maintained as an open-source.

The common experience with open-source is that no one wants to pay for it, but they will happily use it for free.

Titanium JSON-LD 1.1 Processor & API

An implementation of the JSON-LD 1.1 (JSON-based Serialization for Linked Data) specification in Java utilizing Jakarta JSON Processing.

Goals

Status

Java 11 CI Android (Java 8) CI CodeQL Codacy Badge Codacy Badge Maven Central License

Extensions

Table of Contents

Conformance

FeatureTestsPassStatusNotes
Expansion373373100%
Compaction243243100%
Flattening5555100%
JSON-LD to RDF45345199.5%<ul><li>te075 - @vocab as blank node identifier</li><li>tli12 - List with bad @base</li></ul>
RDF to JSON-LD5151100%
Framing898898.8%<ul><li>t0059 - @embed: @last</li></ul>
Remote Document and Context Retrieval181794.4%<ul><li>t0013 - HTML document</li></ul>

See EARL results from the JSON-LD 1.1 Test Suite for more details.

Examples

Titanium provides high-level JsonLd API to interact with the processor.

Transformations


// Expansion
JsonLd.expand("https://w3c.github.io/json-ld-api/tests/expand/0001-in.jsonld")
      .ordered()
      .get();

JsonLd.expand("file:/home/filip/document.json")    // HTTP(S) and File schemes supported
      .context("file:/home/filip/context.jsonld")  // external context
      .get();

// Compaction
JsonLd.compact("https://example/expanded.jsonld", "https://example/context.jsonld")
      .compactToRelative(false)
      .get();

// Flattening
JsonLd.flatten("https://example/document.jsonld").get();

// JSON-LD to RDF
JsonLd.toRdf("https://example/document.jsonld").get();

// RDF to JSON-LD
JsonLd.fromRdf("https://example/document.nq").options(options).get();

// Framing
JsonLd.frame("https://example/document.jsonld", "https://example/frame.jsonld").get();

Local JSON Document

Document document = JsonDocument.of(InputStream) or JsonDocument.of(Reader) ...

JsonLd.expand(document).get();

JsonLd.compact(document, contextDocument).get();
...

Processing Timeout [experimental]

A processor gets terminated eventually after a specified time. Please note the duration does not cover DocumentLoader processing time. You have to set-up a read timeout separately.

// since 1.4.0
JsonLd.expand(...).timeout(duration)...get();

HTTP Document Loader Timeout

Configure and set a custom HTTP document loader instance.

// since 1.4.0 - set read timeout
static DocumentLoader LOADER = HttpLoader.defaultInstance().timeount(Duration.ofSeconds(30));
...
JsonLd.expand(...).loader(LOADER).get();

Document caching

Configure LRU-based cache for loading documents. The argument determines size of the LRU-cache.

// since 1.4.0
JsonLd.toRdf("https://example/document.jsonld").loader(new LRUDocumentCache(loader, capacity)).get();

You can share an instance of LRUDocumentCache among multiple calls to reuse cached documents.

// since 1.4.0
DocumentLoader cachedLoader = new LRUDocumentCache(loader, capacity);

JsonLd.toRdf("https://example/document.jsonld").loader(cachedLoader).get();
JsonLd.toRdf("https://example/another-document.jsonld").loader(cachedLoader).get();

Undefined Terms Processing Policy

Set processing policy on undefined terms. Ignore by default.

// since 1.4.1
JsonLd.expand(...).undefinedTermsPolicy(Fail|Warn|Ignore).get();

Installation

Titanium

Maven

Java 11+

<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>titanium-json-ld</artifactId>
    <version>1.4.1</version>
</dependency>

Gradle

Java 8+, Android API Level >=24

implementation("com.apicatalog:titanium-json-ld-jre8:1.4.1")

JSON-P Provider

Add JSON-P provider, if it is not on the classpath already.

Maven

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.json</artifactId>
    <version>2.0.1</version>
</dependency>

Gradle

implementation("org.glassfish:jakarta.json:2.0.1")

Documentation

javadoc

Contributing

All PR's welcome!

Building

Fork and clone the project repository.

Java 11

> cd titanium-json-ld
> mvn clean package

Java 8

> cd titanium-json-ld
> mvn -f pom_jre8.xml clean package

Resources

Commercial Support

Commercial support is available at filip26@gmail.com