Simplify nested objects and references using URLs as identifiers
A Linked Object is an object that you retrieve from a URL, with the URL serving as its identifier. This approach allows for more efficient handling of nested objects and references, enabling independent updates and reuse across multiple contexts.
Linked Objects offer several advantages over traditional methods
By using URLs as identifiers, developers can easily reference and manage nested objects, resulting in cleaner and more organized code.
Linked Objects can be updated independently of one another, ensuring that changes to one object do not inadvertently affect others.
Since objects are referenced by their URLs, they can be reused across multiple contexts, reducing duplication and promoting consistency.
LION (Linked Objects Notation) is a subset of JSON-LD, allowing for seamless interoperability and an easy upgrade path.
LION is a simple subset of JSON-LD, designed to avoid most of its complexity and enable developers to get started quickly using a familiar notation. LION is compatible with JSON-LD and offers a full upgrade path.
<script type="application/ld+json">
{
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
</script>
<script type="application/ld+json">
{
"@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"
}
}
</script>
@id is the URL of the object. It can also be written as "id". The @id can be absolute or relative. @id is optional but recommended, and makes an object into a Linked Object.
@type is the type for that object. It can also be written as "type". @type normally maps to a URL. Type is optional.
@context is optional. It provides full compatibility with JSON-LD and maps various items in the object to URLs in a more readable way.
Full details on @id, @type and @context can be found in the JSON-LD specification
Install the Linked Objects library via npm and start using it in your project
npm install linkedobjects
import {
create,
fetch,
update,
deleteObject,
importJSON,
exportJSON
} from 'linkedobjects'
Creates a new Linked Object with the given id and data. Returns the created object.
objects: The container object where the Linked Object will be created
id: The URL identifier for the Linked Object
data: The data to be stored in the Linked Object
Fetches a Linked Object with the specified id from the objects container. Returns the object if found, or null otherwise.
objects: The container object where the Linked Object is stored
id: The URL identifier for the Linked Object
Updates an existing Linked Object with the specified id in the objects container with the provided data. Returns the updated object if found, or null otherwise.
objects: The container object where the Linked Object is stored
id: The URL identifier for the Linked Object
data: The new data to be merged with the existing Linked Object
Deletes a Linked Object with the specified id from the objects container. Returns true if the object was successfully deleted, or false otherwise.
objects: The container object where the Linked Object is stored
id: The URL identifier for the Linked Object
Imports Linked Objects from a JSON string and adds them to the objects container.
objects: The container object where the Linked Objects will be stored
json: The JSON string containing the Linked Objects to be imported
Exports the Linked Objects from the objects container into a JSON string.
objects: The container object containing the Linked Objects to be exported
Try out the Linked Objects library with our interactive demo showcasing all core functions.
View Demo
Linked Objects is open-source under the MIT license. We welcome contributions and feedback.
GitHub Repository