How to filter JSON-LD object array with JSON-LD frames?

Viewed 186

I have been spending two days trying to do the following, without success.

I have this example JSON-LD document:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3c-ccg.github.io/ldp-bbs2020/context/v1",
    "https://mycontext.com/credentials/v1"
  ],
  "type": ["VerifiableCredential"],
  "issuer": "did:example:issuer",
  "issuanceDate": "2020-01-01T00:00:00Z",
  "expirationDate": "2029-12-31T23:59:59Z",
  "credentialSubject": {
    "id": "did:example:subject",
    "type": ["ExampleCredential"],
    "values": [
      {
        "a": 1,
        "b": 2,
        "c": 3
      },
      {
        "a": 4,
        "b": 5,
        "c": 6
      }
    ]
  }
}

and the following JSON-LD context (hypothetically retrievable at https://mycontext.com/credentials/v1):

{
  "@context": {
    "@version": 1.1,
    "@protected": true,

    "schema": "https://schema.org/",

    "ExampleCredential": {
      "@id": "https://mycontext.com/credentials#ExampleCredential",

      "@context": {
        "@version": 1.1,
        "@protected": true,

        "type": "@type",

        "values": "@nest",
        "a": {
          "@id": "https://mycontext.com/credentials#a",
          "@type": "schema:example_a",
          "@nest": "values"
        },
        "b": {
          "@id": "https://mycontext.com/credentials#b",
          "@type": "schema:example_b",
          "@nest": "values"
        },
        "c": {
          "@id": "https://mycontext.com/credentials#c",
          "@type": "schema:example_c",
          "@nest": "values"
        }
      }
    }
  }
}  

Furthermore, I am trying to use the following JSON-LD frame to filter only the element in the credential that has the field a equal to 1:

{
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3c-ccg.github.io/ldp-bbs2020/context/v1",
    "https://mycontext.com/credentials/v1"
  ],
  "@explicit": true,
  "type": ["VerifiableCredential"],
  "issuer": "did:example:issuer",
  "issuanceDate": {},
  "expirationDate": {},
  "credentialSubject": {
    "id": "did:example:subject",
    "@explicit": true,
    "type": ["ExampleCredential"],
    "values": [
      {
        "a": 1,
        "b": {},
        "c": {}
      }
    ]
  }
}

I am using the jsonld package to perform these operations, and the final result that I would like to get corresponds to the initial document, but with the values field filtered to only contain the first object in the list. This is just the last of the attempts, and I have tried everything from "@container": "@set" to @nest, but clearly I am missing something. What is the right way to format the context and/or the frame so that I can achieve the expected result? Aka, what is the right way to express a relationship in a context in which the child is a list of objects of a specific type?

Thanks!

0 Answers
Related