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

**URL:** <https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290>\
**Category:** Solid App Development FAQs\
**Created:** [February 17, 2019, 11:20am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290 "2019-02-17T11:20:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bourgeoa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/bourgeoa/32/291_2.png) [@bourgeoa](https://forum.solidproject.org/u/bourgeoa)\
**Post date:** [February 17, 2019, 11:20am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/1 "2019-02-17T11:20:54Z")

</div>

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

```
bourgeoa
@bourgeoa
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
@timbl
00:11
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](https://bourgeoa.solid.community/public/tiddlers/main/alainLd.json) 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 ?

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [February 17, 2019, 11:23am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/2 "2019-02-17T11:23:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bourgeoa](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/bourgeoa/32/291_2.png) [@bourgeoa](https://forum.solidproject.org/u/bourgeoa)\
**Post date:** [February 17, 2019, 11:54am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/3 "2019-02-17T11:54:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![happybeing](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/happybeing/32/59_2.png) [@happybeing](https://forum.solidproject.org/u/happybeing)\
**Post date:** [February 17, 2019, 3:37pm UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/4 "2019-02-17T15:37:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon36056958](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@anon36056958](https://forum.solidproject.org/u/anon36056958)\
**Post date:** [April 7, 2019, 4:38am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/5 "2019-04-07T04:38:10Z")

</div>

> **[solid/chat](https://gitter.im/solid/chat?at=5ca9663a759abc043c7c0d87)**
>
> @timbl: @sscheper Saw your question why RDF — RDF is the data model. Turtle is one serialization. Turtle is very simple. You can parse JSON/LD and RDF/a into RDF, and then serialize them into turtle if you want. The abstract model is what...

---

<div class="post-metadata">

**Author:** ![aveltens](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/aveltens/32/3987_2.png) [@aveltens](https://forum.solidproject.org/u/aveltens)\
**Post date:** [April 7, 2019, 10:09am UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/6 "2019-04-07T10:09:39Z")

</div>

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:

```auto
curl -H accept:application/ld+json https://bourgeoa.solid.community/public/tiddlers/main/alain10.ttl

```

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

---

<div class="post-metadata">

**Author:** ![anon36056958](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@anon36056958](https://forum.solidproject.org/u/anon36056958)\
**Post date:** [April 7, 2019, 12:06pm UTC](https://forum.solidproject.org/t/how-to-write-a-json-ld-object-into-rdf-objects-in-rdflib-js/1290/7 "2019-04-07T12:06:29Z")

</div>

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.
