Untitled

mail@pastecode.io avatar
unknown
python
14 days ago
522 B
6
Indexable
Never
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')
Leave a Comment