Skip to content

gkostkowski/jsonld-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON-LD Demo

Repository contains scripts and information useful for starting with JSON-LD tools (Python and CLI).

Tools

Python

PyLD

The official Python library supporting version 1.1 is pyLD.

demo

demo.py presents available features of pyLD and JSON-LD 1.1:

  1. compaction,
  2. compaction using remote context file,
  3. expansion,
  4. expansion of remote file,
  5. flattening,
  6. flattening and compaction,
  7. framing,
  8. normalization,
  9. conversion between serialization formats: JSON-LD -> N-Quads,
  10. conversion between serialization formats: N-Quads -> JSON-LD.
RDF Serialization formats

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

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.

CLI

jsonld-cli

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.

examples
  1. 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
  1. Compact local file using remote context file:
jsonld compact \
    -c http://json-ld.org/contexts/person.jsonld \
    data/file02-exmanded.jsonld

pyLD

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.

RDF to JSON-LD

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

About

Introduction to JSON-LD tools in Python

Topics

Resources

License

Stars

Watchers

Forks

Languages