How to write a json-ld Object into RDF objects in rdflib.js?

I am looking for help using rdflib.js and json-ld, here is the question and answer I got from the chat :

Feb 15 22:30
I have a json-ld object is there a way to serialise it to N3 with rdflib.js or can I save it like that in Solid as .JSON and parse it with rdflib.js
Tim Berners-Lee
You can write it into RDF objects in rdflib.js and then serialize it as N3, yes - rdfllib.js hs an n3 serializer 

I do not find how to write a Json Object or this file to the let store = $rdf.graph().
I tried solidFile.fetchAndParse and $rdf.parse and both refuse application/json

Do I have to write to the store statement by statement ?

Not really my area, but would it work to store in Turtle and then request JSON-LD when you retrieve?

1 Like

That is the second part of the problem, I also don’t know how to request json-ld when I retrieve but I did not try it.

I’m not sure how to do it either sorry, it may be to do with the request headers, but I think you can get whatever format you prefer from rdflib.js (because the fetcher has support for returning different formats). I haven’t used it so can’t tell you how, but I’ve seen it in the code.

1 Like

Keep in mind that Node Solid Server can serialize RDF in several formats, whereas it usually stores turtle internally. But still you can request JSON-LD for any resource with the correct Accept-Header:

curl -H accept:application/ld+json

Speaking of this, the file ending in the URL is missleading and should be removed, since the resources are independent of their representation.

1 Like

iirc the server only uses the file type extension if the accept header is not present, although maybe that’s wrong.

I think the server should allow “.” characters in the filename but not police the names. So for example if someone were to use “*.turtle” that could also be misleading but the server should not care.

But in the ecosystem envisioned, as I understand it, the server is intended to stay as simple as possible while the clients grow in complexity.

So while questions like file type extensions are important I for one would like to see more discussion about apps that devs could collaborate on.

I only posted the link to the chat about json-ld vs turtle here in the forum because it well described some fundamental differences that I thought should be searchable here.