Skip to content
JSON-LD processor for PHP
PHP
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Exception Fix DocBlock Jan 17, 2016
Test Use 1.0 test suite and fix base URL to account for the change to HTTP… Jan 28, 2018
.gitignore Fix line endings (\r\n -> \n) Sep 14, 2014
.travis.yml Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
DefaultDocumentFactory.php Coding style fixes Dec 28, 2015
Document.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
DocumentFactoryInterface.php Coding style fixes Dec 28, 2015
DocumentInterface.php Fix and improve DocBlocks Dec 30, 2015
DocumentLoaderInterface.php Inject DocumentLoader into Processor Oct 10, 2016
FileGetContentsLoader.php
Graph.php
GraphInterface.php
JsonLD.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
JsonLdSerializable.php Remove unused imports Dec 30, 2015
LICENSE Updated copyright to 2016 Jan 15, 2016
LanguageTaggedString.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
NQuads.php
Node.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
NodeInterface.php Minor improvements and fixes Dec 30, 2015
Processor.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
Quad.php Fix and improve DocBlocks Dec 30, 2015
QuadParserInterface.php Change coding style to PSR-2 Dec 13, 2012
QuadSerializerInterface.php Change coding style to PSR-2 Dec 13, 2012
README.md Update README.md (#84) Nov 18, 2018
RdfConstants.php
RemoteDocument.php Fix and improve DocBlocks Dec 30, 2015
TypedValue.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
Value.php Rename Object to JsonObject to fix conflict with PHP 7.2 Nov 18, 2018
composer.json
phpunit.xml.dist Fix line endings (\r\n -> \n) Sep 14, 2014

README.md

JsonLD Build Status

JsonLD is a fully conforming JSON-LD processor written in PHP. It is extensively tested and passes the official JSON-LD test suite.

There's an online playground where you can evaluate the processor's basic functionality.

Additionally to the features defined by the JSON-LD API specification, JsonLD supports framing (including value matching, deep-filtering, aggressive re-embedding, and named graphs) and an experimental object-oriented interface for JSON-LD documents.

Installation

The easiest way to install JsonLD is by requiring it with Composer.

composer require ml/json-ld

... and including Composer's autoloader to your project

require('vendor/autoload.php');

Of course, you can also download JsonLD as ZIP archive from Github.

JsonLD requires PHP 5.3 or later.

Usage

The library supports the official JSON-LD API as well as a object-oriented interface for JSON-LD documents (not fully implemented yet, see issue #15 for details).

All classes are extensively documented. Please have a look at the source code.

// Official JSON-LD API
$expanded = JsonLD::expand('document.jsonld');
$compacted = JsonLD::compact('document.jsonld', 'context.jsonld');
$framed = JsonLD::frame('document.jsonld', 'frame.jsonld');
$flattened = JsonLD::flatten('document.jsonld');
$quads = JsonLD::toRdf('document.jsonld');

// Output the expanded document (pretty print)
print JsonLD::toString($expanded, true);

// Serialize the quads as N-Quads
$nquads = new NQuads();
$serialized = $nquads->serialize($quads);
print $serialized;

// And parse them again to a JSON-LD document
$quads = $nquads->parse($serialized);
$document = JsonLD::fromRdf($quads);

print JsonLD::toString($document, true);

// Node-centric API
$doc = JsonLD::getDocument('document.jsonld');

// get the default graph
$graph = $doc->getGraph();

// get all nodes in the graph
$nodes = $graph->getNodes();

// retrieve a node by ID
$node = $graph->getNode('http://example.com/node1');

// get a property
$node->getProperty('http://example.com/vocab/name');

// add a new blank node to the graph
$newNode = $graph->createNode();

// link the new blank node to the existing node
$node->addPropertyValue('http://example.com/vocab/link', $newNode);

// even reverse properties are supported; this returns $newNode
$node->getReverseProperty('http://example.com/vocab/link');

// serialize the graph and convert it to a string
$serialized = JsonLD::toString($graph->toJsonLd());

Commercial Support

Commercial support is available on request.

You can’t perform that action at this time.