Simpler handling
Refer to an object by its URL instead of carrying it around. Code that manages nested data gets shorter and clearer.
A Linked Object is an object you fetch from a URL, with the URL as its identifier. Give an object an @id and it can be pointed at, updated on its own, and reused anywhere. That is the whole idea, and it is still plain JSON.
Valid JSON-LD 1.1, without the ceremony: no context to fetch, no vocabulary to pick first. Add them later if you need RDF.
Why linked objects
When an object lives inside another, every copy has to be kept in step. When it has its own URL, there is one of it, and everything else refers to it.
Refer to an object by its URL instead of carrying it around. Code that manages nested data gets shorter and clearer.
Change one object without touching the ones that point at it. Nothing else has to be rewritten.
The same object can appear in many places, because each place holds a reference and not a copy.
Every LION document is JSON-LD. Start simple, and add a context when you want the full linked-data toolchain.
Linked Object Notation
LION is a small subset of JSON-LD, chosen to leave out most of its complexity. If you can write JSON you can write LION. Full details of the keywords are in the JSON-LD specification.
the name
Absolute or relative, and may be written id. Optional but recommended: it is what makes an object a Linked Object.
the kind
May be written type, and normally maps to a URL. Optional.
the upgrade
Optional. Add it for full JSON-LD. Without one, processors that need RDF read bare property names against the default vocabulary urn:solid:.
{
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
{
"@id": "http://example.org/album/1",
"name": "Example Album",
"releaseDate": "2023-01-01",
"tracks": [
{
"@id": "http://example.org/track/1",
"@type": "Track",
"name": "Track 1",
"duration": "3:45"
},
{
"@id": "http://example.org/track/2",
"@type": "Track",
"name": "Track 2",
"duration": "4:32"
}
],
"artist": {
"@id": "http://example.org/artist/1",
"@type": "Artist",
"name": "Example Artist",
"birthDate": "1990-01-01"
}
}
The library
A small JavaScript library for creating, finding and updating Linked Objects in memory, wherever they sit in a nested structure, and for moving them in and out of JSON.
npm install linkedobjects
import { create, fetch, update, deleteObject, importJSON, exportJSON } from 'linkedobjects'
| Function | What it does |
|---|---|
create(objects, id, data) | Creates a Linked Object with that id and data, and returns it. |
fetch(objects, id) | Finds the object with that id, however deeply nested. Returns it, or null. |
update(objects, id, data) | Merges new data into the object with that id. Returns it, or null. |
deleteObject(objects, id) | Removes the object with that id. Returns true if it was deleted. |
importJSON(objects, json) | Reads Linked Objects from a JSON string into the container. |
exportJSON(objects) | Writes the container's Linked Objects out as a JSON string. |
Background
The idea of naming JSON objects with URLs is older than JSON-LD. LION keeps that core and leaves the rest optional.
Try the functions in your browser, or read the specification and the source. Issues and contributions are welcome.