Repository contains scripts and information useful for starting with JSON-LD tools (Python and CLI).
The official Python library supporting version 1.1 is pyLD.
demo.py presents available features of pyLD and JSON-LD 1.1:
- compaction,
- compaction using remote context file,
- expansion,
- expansion of remote file,
- flattening,
- flattening and compaction,
- framing,
- normalization,
- conversion between serialization formats: JSON-LD -> N-Quads,
- conversion between serialization formats: N-Quads -> JSON-LD.
pyLD provides possibility to convert from or to JSON-LD.
Currently, only N-Quads
and N-Triples
are supported. Conversion for
other formats can be added using jsonld.register_rdf_parser
function.
Rdflib supports version 1.0 of JSON-LD. It does not provide support for current JSON-LD 1.1 version, which introduces important improvements. There are some plans to use pyLD as parser for rdflib and fulfill in that way the need for JSON-LD 1.1 support in rdflib.
jsonld-cli is a CLI tool based on jsonld.js.
It turns out that jsonld-cli ignores input file type. If you need to read RDF non-JSON-LD file, you may want to use cli.py instead.
- Convert remote jsonld file to nquads format:
jsonld format \
-f nquads \
https://raw.githubusercontent.com/w3c/json-ld-syntax/main/examples/Sample-JSON-LD-document-to-be-expanded.jsonld
- Compact local file using remote context file:
jsonld compact \
-c http://json-ld.org/contexts/person.jsonld \
data/file02-exmanded.jsonld
pyLD does not provide official CLI. cli.py is a script adding CLI support for pyLD, proposed by Wes Turner. Additionally, script registers custom parsers for RDF serialization formats.
To convert RDF file in any serialization format (e.g. turtle),
use --rdf-to-jsonld
option. E.g. to convert void.ttl file:
python cli.py --rdf-to-jsonld void.ttl --format text/turtle -o void.jsonld