Using Solid with JSON-LD

For web developers that are not (yet) accustomed to Linked Data it is much easier to build apps that can handle JSON trees.

Luckily there is JSON-LD, a JSON serialization of RDF, and Node Solid Server is able to serialize a resource as such:

curl --header Accept:application/ld+json https://angelo.veltens.org/profile/card

This will give you the data from my profile as JSON-LD.

Using JSON-LD Framing, you can easily apply a context and structure that fits your client app.

{
  "id": "#me",
  "type": [
    "schema:Person",
    "foaf:Person"
  ],
  "photo": "me.jpg",
  "name": "Angelo Veltens"
}

This way you can handle Linked Data as if it was just regular JSON. (Because it is, now).

You can find a running example in the JSON-LD playground.

Source: https://angelo.veltens.org/articles/2019/04/solid-with-jsonld

13 Likes

Yup; just had a related conversation, which TBL answered in the Solid Gitter Chat.

I much prefer the JSON-LD syntax and form; makes working with Linked Data much more exciting imo.

Fun stuff!

2 Likes

Looks good. How would this work in practice? Are there any examples of apps that use JSON-LD?

I am currently working on libraries that are based on JSON-LD. But this ist still in a very early / experimental phase.

OK thanks. Iā€™m not familiar with react. Could you provide an example using JS? For example, can i do an ajax request and retrieve the results as JSON-LD as opposed to turtle? If so, how?

You just have to set the accept header to Accept:application/ld+json. You can then use jsonld.js on client side.

Here is a JSFiddle that demonstrates applying a client context after loading data from backend

https://jsfiddle.net/aveltens/d3tzfhjx/