Untitled
unknown
python
a year ago
522 B
13
Indexable
from rdflib import Graph
import json
def jsonld_to_ntriples(input_file, output_file):
"""
Use rdflib to convert a JSON-LD file to N-Triples format with UTF-8 encoding.
input_file: Path to JSON-LD file
output_file: Path to output file in N-Triples format
"""
g = Graph()
with open(input_file, 'r', encoding='utf-8') as f:
jsonld_data = json.load(f)
g.parse(data=json.dumps(jsonld_data), format='json-ld')
g.serialize(destination=output_file, format='nt', encoding='utf-8')Editor is loading...
Leave a Comment