https://npm.runkit.com/rdf-translator uses https://bitbucket.org/alexstolz/rdf-translator, but it stops maintaining.
Is there an alternative written in JS?
https://npm.runkit.com/rdf-translator uses https://bitbucket.org/alexstolz/rdf-translator, but it stops maintaining.
Is there an alternative written in JS?
I think https://rdf.js.org/ is a good resource for finding stuff like this in general, but rdflib.js allows you to read JSON-LD and write to Turtle at least (not the other way around though IIRC).
rdflib.js can both read and write JSON-LD. Here’s how:
function turtle2jsonld( turtleString, store, uri ){
return new Promise(resolve=>{
$rdf.parse( turtleString, store, uri, "text/turtle", e => {
if(e) { console.log("Parse Error! "); return resolve(e) }
$rdf.serialize(null,store, uri,'application/ld+json',(e,s)=>{
if(e) { console.log("Serialize Error! "); return resolve(e) }
return resolve(s)
})
})
})
}
function jsonld2turtle( jsonldString, store, uri ){
return new Promise(resolve=>{
$rdf.parse( jsonldString, store, uri, "application/ld+json", e => {
if(e) { console.log("Parse Error! "); return resolve(e) }
$rdf.serialize(null,store, uri,'text/turtle',(e,s)=>{
if(e) { console.log("Serialize Error! "); return resolve(e) }
return resolve(s)
})
})
})
}
Hi @jeffz , seems it is not working, I’ve created a runkit note for it https://github.com/linkeddata/rdflib.js/issues/364#issuecomment-568694710