Linked Objects

Simplify nested objects and references using URLs as identifiers

GitHub repo size GitHub contributors GitHub stars

What is a Linked Object?

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.

Why Use Linked Objects?

Linked Objects offer several advantages over traditional methods

🔗

Simplified Handling

By using URLs as identifiers, developers can easily reference and manage nested objects, resulting in cleaner and more organized code.

♻️

Independent Updates

Linked Objects can be updated independently of one another, ensuring that changes to one object do not inadvertently affect others.

🔄

Reusability

Since objects are referenced by their URLs, they can be reused across multiple contexts, reducing duplication and promoting consistency.

🔌

JSON-LD Compatible

LION (Linked Objects Notation) is a subset of JSON-LD, allowing for seamless interoperability and an easy upgrade path.

Linked Object Notation (LION)

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.

Examples

Basic Linked Object
<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>
Complex Nested Example
<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

@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

@type is the type for that object. It can also be written as "type". @type normally maps to a URL. Type is optional.

@context

@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

Getting Started

Install the Linked Objects library via npm and start using it in your project

Installation
npm install linkedobjects
Import Functions
import {
  create,
  fetch,
  update,
  deleteObject,
  importJSON,
  exportJSON
} from 'linkedobjects'

API Reference

create(objects, id, data)

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

fetch(objects, id)

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

update(objects, id, data)

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

deleteObject(objects, id)

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

importJSON(objects, json)

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

exportJSON(objects)

Exports the Linked Objects from the objects container into a JSON string.

objects: The container object containing the Linked Objects to be exported

Resources & References

🎯 Demo

Try out the Linked Objects library with our interactive demo showcasing all core functions.

View Demo

🤝 Contribute

Linked Objects is open-source under the MIT license. We welcome contributions and feedback.

GitHub Repository