Skip to content


Subversion checkout URL

You can clone with
Download ZIP
JSON-LD processor for PHP
Failed to load latest commit information.
Exception Fix typo
Test Support named graphs when parsing JSON-LD to Document
.gitignore Fix line endings (\r\n -> \n)
.travis.yml Fix line endings (\r\n -> \n)
DefaultDocumentFactory.php Introduce DocumentFactory
Document.php Support named graphs when parsing JSON-LD to Document
DocumentFactoryInterface.php Introduce DocumentFactory
DocumentInterface.php Make interfaces more fluent
FileGetContentsLoader.php Add */*; q=0.1 to Accept header and remove code duplication
Graph.php Support named graphs when parsing JSON-LD to Document
GraphInterface.php Support named graphs when parsing JSON-LD to Document
JsonLD.php Move constants defining the default graph/merged graph identifiers to…
JsonLdSerializable.php Grrr... Forgot to add JsonLdSerializable in last commit
LanguageTaggedString.php Make interfaces more fluent
NQuads.php Blank node identifiers in N-Quads can begin with a digit as well
Node.php Normalize scalar values to Value objects
NodeInterface.php Make interfaces more fluent
Processor.php Fix specification bug json-ld/
Quad.php Change coding style to PSR-2
QuadParserInterface.php Change coding style to PSR-2
QuadSerializerInterface.php Change coding style to PSR-2 Tweak README
RdfConstants.php Convert "partial" lists from RDF to JSON-LD
RemoteDocument.php Remove another unnecessary use statement and a unused variable
TypedValue.php The default value of useNativeTypes has been changed to false
Value.php Do not overwrite @type when converting to RDF
composer.json Include the "json-ld/tests" package instead of cloning the tests from…
phpunit.xml.dist Fix line endings (\r\n -> \n)

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.


The easiest way to use JsonLD is to integrate it as a dependency in your project's composer.json file:

    "require": {
        "ml/json-ld": "1.*"

Installing is then a matter of running composer

php composer.phar install

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


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

JsonLD requires PHP 5.3 or later.


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('');

// get a property

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

// link the new blank node to the existing node
$node->addPropertyValue('', $newNode);

// even reverse properties are supported; this returns $newNode

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

Commercial Support

Commercial support is available on request.

Something went wrong with that request. Please try again.