1

Is it possible to convert Json-Ld data to different RDF/XML format by using 'jsonld' package https://www.npmjs.com/package/jsonld?

In the documentation, I found possible to inject RDF parser.

// register a custom promise-based RDF parser
jsonld.registerRDFParser(contentType, async input => {
  // parse input into a jsonld.js RDF dataset object...
  return new Promise(...);
});

but I'm not sure whether we could use it to convert data from Json-Ld to different format; or to convert from different format to Json-Ld.

My main goal is to create converter in both directions between Json-Ld and RDF/XML, N3, Turtle, so different suggestions are also welcome

Chen
  • 2,958
  • 5
  • 26
  • 45
Przemek
  • 11
  • 2
  • are you doing this programmatically (in-line for an application) or is it OK to do it external to a program and save as a unique file? – Jay Gray Jul 05 '18 at 10:10
  • 'programmatically' - it is one step of bigger process – Przemek Jul 09 '18 at 09:54
  • very difficult. my advice - do it externally so you can check; then inject as needed. There are many reasons why you could get an error with a programmatic method. Here is a good resource for external: http://rdf-translator.appspot.com/ – Jay Gray Jul 09 '18 at 13:06

1 Answers1

0

You can use rdf-translator: https://npm.runkit.com/rdf-translator

Example:

var rdfTranslator = require('rdf-translator');
var str = `
{
  "@context":
  {
    "name": "http://schema.org/name",
    "image": {
      "@id": "http://schema.org/image",
      "@type": "@id"
    },
    "homepage": {
      "@id": "http://schema.org/url",
      "@type": "@id"
    }
  },
  "@id": "http://example.org/something",
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/",
  "image": "http://manu.sporny.org/images/manu.png"
}
`
const data = await rdfTranslator(str, 'json-ld', 'n3')
林东吴
  • 171
  • 1
  • 8