Skip to content

Prevent leading slash when serializing relative URIs in JSON-LD #3273

@elichad

Description

@elichad

I'm working with JSON-LD data which uses relative URIs as identifiers (example). The identifiers may be paths (like data/results.csv) or local identifiers, which in our case usually start with # (like #alice).

I want to parse this data into a Graph, run SPARQL on it to update it, then serialize it back to JSON-LD.

If I define a base URI (say https://example.org/) and use that both when parsing and serializing the data, I expect that the output will be the same (except for the ordering of @graph). However, I find that the relative @ids are now all prefixed with /, for example:

{
  "@context": "https://w3id.org/ro/crate/1.2/context",
  "@graph": [
    {
      "@id": "/data.csv",
      "@type": "File",
      "name": "Rainfall data for Katoomba, NSW Australia February 2022",
      "encodingFormat": "text/csv",
      "license": {"@id": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/"}
    },
    {
      "@id": "/#local-identifier",
      "@type": "Organization",
      "name": "Blah blah",
    },
    ...
  ]
}

This happens regardless of whether the base URI has a trailing slash.

Is there any way to strip off the leading slash in the relative URIs when serializing?

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