Skip to content

Instantly share code, notes, and snippets.

@epoz
Created January 29, 2021 20:52
Show Gist options
  • Select an option

  • Save epoz/c4d150014732e95eefd44a74593e6a36 to your computer and use it in GitHub Desktop.

Select an option

Save epoz/c4d150014732e95eefd44a74593e6a36 to your computer and use it in GitHub Desktop.
Scan a NDJSON file of JSON-LD data and convert it to Turtle
# Make sure you have the rdflib and rdflib-jsonld libraries installed
# This gist is the Pythn equivalent of Mark's repo from here: https://github.com/mightymax/ndjson2ttl
# As referenced in this tweet: https://twitter.com/markuitheiloo/status/1355252255327449090
import sys
from rdflib import Graph
for line in open(sys.argv[1]):
g = Graph().parse(data=line, format="json-ld")
print(g.serialize(format="n3").decode("utf8"))
@epoz
Copy link
Copy Markdown
Author

epoz commented Jan 29, 2021

You can run the script above by calling it with the file to convert as the first argument, for example:
python ndjson2nt.py iconclass.ndjson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment