Skip to content

Enhancement: Use rdflib's JSON-LD parser for full context expansion #2

@melvincarvalho

Description

@melvincarvalho

Current Behavior

The parseJsonLdToStore() function uses a simple manual parser that only expands the schema: prefix:

const typeUri = node['@type'].replace('schema:', 'http://schema.org/')

This means JSON-LD using other vocabularies (like W3C Verifiable Credentials) must use full URIs instead of relying on @context expansion.

Proposed Enhancement

Use rdflib's built-in JSON-LD parser which handles full context expansion:

$rdf.parse(jsonLdString, store, baseUri, 'application/ld+json')

Benefits

  • Full JSON-LD context expansion
  • Support for any vocabulary without code changes
  • Proper handling of @type arrays
  • Standards-compliant parsing

Considerations

  • Network latency: Context URLs need to be fetched (could cache common ones)
  • Offline support: Would need bundled/cached contexts
  • Async: $rdf.parse() with remote contexts is async

Possible Approach

  1. Use $rdf.parse() for full JSON-LD support
  2. Bundle common contexts (schema.org, credentials/v1, etc.)
  3. Fall back to simple parser if context fetch fails

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions