Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

LDflex for Solid

Simple access to data in Solid pods through LDflex expressions

npm version Build Status Coverage Status Dependency Status

This library is a configuration of the LDflex language for the Solid ecosystem. It configures LDflex with:

  1. JSON-LD context for Solid
  2. a Solid-authenticated query engine (Comunica or rdflib.js)
  3. useful data paths for Solid

LDflex expressions occur for example on Solid React components, where they make it easy for developers to specify what data they want to show. They can also be used as an expression language in any other Solid project or framework.

Creating data paths

Once you obtain the object, start writing data paths from the following entry points.

The user entry point

The path can query data about the currently logged in user, such as:

  • yields the user's first name(s)
  • yields the user's email address(es)
  • yields the user's friend(s)
  • yields the user's friends' first name(s)

The any URL entry point

The[url] path can query data about any subject by URL, such as:


Specifying properties

As you can see in the above examples, an LDflex path starts with an entry point and is followed by property names, which can be:

  • abbreviations such as firstName (which expands to
  • prefixed names such as foaf:givenName (which expands to
  • full URLs such as

The abbreviations and prefixed names are expanded using a JSON-LD context. You can find some inspiration about what to ask for in this context.

You can access data using any vocabulary you want and, when included in the JSON-LD context, in multiple ways. For example:

  • FOAF:
  • vCard:
  • Custom:

The traditional colon syntax for prefixes (schema:name) can be substituted with an underscore (schema_name) or dollar sign (schema$name). This is because JavaScript keys with a colon require quotes (user['schema:name']) whereas underscores and dollar signs can be used freely (user.schema_name, user.schema$name).


npm install @solid/query-ldflex


Within Node.js environments

const { default: data } = require('@solid/query-ldflex');

const ruben = data[''];

async function showProfile(person) {
  const label = await person.label;
  console.log(`\nNAME: ${label}`);

  for await (const type of person.type)
    console.log(`  - ${type}`);

  for await (const name of person.friends.firstName)
    console.log(`  - ${name} is a friend`);

If, instead of Comunica, you want to use the rdflib.js query engine, install @ldflex/rdflib as a dependency of your project and use

const { default: data } = require('@solid/query-ldflex/lib/exports/rdflib');

When creating browser builds, it can be easier to simply tell webpack to replace @ldflex/comunica by @ldflex/rdflib.

In the browser

<script src="solid-auth-client.bundle.js"></script>
<script src="solid-query-ldflex.bundle.js"></script>
document.addEventListener('DOMContentLoaded', async () => {
  const user =;
  alert(`Welcome, ${await user.firstName}!`);

To replace Comunica by rdflib.js, opt for

<script src="solid-auth-client.bundle.js"></script>
<script src="rdflib.min.js"></script>
<script src="solid-query-ldflex.rdflib.js"></script>

Adding a custom JSON-LD context

In addition to the default properties, you might want to support your own:

console.log(;       // the raw default JSON-LD context
await{      // add new JSON-LD context
  con: '',
  preferred: 'con:preferredURI',
console.log(await; // the expanded JSON-LD context

// Now we can use both existing and new properties
const ruben =[''];
console.log(await ruben.preferred);

Be aware though that this leads to expressions that are less portable, because they only work when the additional context is added.

Resolving string expressions

LDflex expressions are actual JavaScript—not strings. There are times when strings are more useful though, such as when building declarative components that take LDflex expressions.

The object exports a resolve interface that transforms a string expression into an actual LDflex path. This string is appended to to obtain the resulting path. For example:

  •'.user.firstName') becomes the path
  •'[""].label') becomes the path[""].label

For convenience, the starting dot and quotes inside of brackets can be omitted. If the path is a single URL, quotes and brackets can be omitted. The following strings will all resolve:

  • '.user.firstName'
  • 'user.firstName'
  • '[""].label'
  • '[].label'
  • ''


©2018–present Ruben Verborgh, MIT License.