rdflib-jsonld (Deprecated)
rdflib-jsonld was a plugin for RDFLib that provided JSON-LD 1.0 parsing and serialization capabilities. As of RDFLib 6.0.1 (released September 2021), JSON-LD handling has been integrated directly into the core RDFLib library. The rdflib-jsonld library itself is now 'tombstoned', with version 0.6.2 being the final release that removes all core functionality, leaving only a deprecation warning. It is considered abandoned.
Common errors
-
DeprecationWarning: The rdflib-jsonld package has been integrated into rdflib as of rdflib==6.0.1. Please remove rdflib-jsonld from your project's dependencies.
cause You have both `rdflib-jsonld` and `rdflib>=6.0.1` installed. The `rdflib-jsonld` package is now obsolete and its presence triggers this warning.fixRemove `rdflib-jsonld` from your environment: `pip uninstall rdflib-jsonld`. Ensure your `rdflib` version is 6.0.1 or newer. -
from rdflib_jsonld import ... ImportError: cannot import name 'JSONLDPlugin' from 'rdflib_jsonld' (.../rdflib_jsonld/__init__.py)
cause You are trying to import specific components from `rdflib-jsonld` version 0.6.2 or newer, but its functionality has been deliberately removed. The `__init__.py` file for these versions does not expose any functional modules.fixStop importing directly from `rdflib_jsonld`. JSON-LD functionality is now automatically available when using `rdflib.Graph().parse(format='json-ld')` or `rdflib.Graph().serialize(format='json-ld')` with `rdflib>=6.0.1`. -
Graph contains 0 triples.
cause When trying to parse JSON-LD data after installing `rdflib-jsonld` version 0.6.2, no triples are added to the graph because the functionality was removed in this 'tombstoning' release.fixUninstall `rdflib-jsonld` (if installed). Ensure you are using `rdflib>=6.0.1`. The core `rdflib` library now handles JSON-LD parsing and serialization natively.
Warnings
- breaking The `rdflib-jsonld` package is deprecated and 'tombstoned'. Version 0.6.2 (the final release) removes all JSON-LD parsing and serialization functionality, instead printing a deprecation warning.
- deprecated For all Python versions above 3.6, the functionality previously provided by `rdflib-jsonld` has been integrated into `rdflib` itself since version 6.0.1. Continuing to install `rdflib-jsonld` is unnecessary and may lead to warnings or unexpected behavior.
- gotcha If you are forced to use Python <= 3.6, you will need to rely on older, unsupported versions of `rdflib-jsonld` (<=0.5.0) with `rdflib 5.0.0`. This setup is not recommended or maintained.
Install
-
pip install rdflib-jsonld -
pip install rdflib>=6.0.1
Imports
- Graph
from rdflib_jsonld import JSONLDPlugin
from rdflib import Graph
Quickstart
from rdflib import Graph
json_ld_data = '''
{
"@context": "http://schema.org/",
"@type": "Person",
"name": "Jane Doe",
"jobTitle": "Professor",
"telephone": "(425) 123-4567",
"url": "http://www.janedoe.com"
}
'''
# Create a graph and parse JSON-LD data
g = Graph().parse(data=json_ld_data, format='json-ld')
print("Graph contains %d triples." % len(g))
# Serialize the graph back to JSON-LD
serialized_json_ld = g.serialize(format='json-ld', indent=4)
print("\nSerialized JSON-LD:")
print(serialized_json_ld)
# Example of querying a triple
from rdflib import URIRef, Literal, Namespace
from rdflib.namespace import RDF
schema = Namespace("http://schema.org/")
for s, p, o in g.triples((None, schema.name, None)):
print(f"Found name: {o}")