rdfsemantic-webjson-ld

Granular control over JSON-LD embeddings


Given the following JSON-LD

{
  "@graph": [
    {
      "@id": "Alice",
      "https://schema.org/givenName": "Alice",
      "https://schema.org/familyName": "Smith"
    },
    {
      "@id": "CorporationA",
      "https://schema.org/founder": [
        {
          "@id": "Alice"
        }
      ],
      "https://schema.org/member": [
        {
          "@id": "Alice"
        }
      ],
      "https://schema.org/employee": [
        {
          "@id": "Alice"
        }
      ]
    }
  ]
}

with the simple frame

{
  "@vocab": "https://schema.org/"
}

is it possible to have more granular control over the embeddings than what's provided via @embed (that is @once, @always, and @never)? More precisely, say I wanted to have an embedding only for the member property, but not for founder or employee. Is it possible without reordering the fields?

From the JSON-LD specification, I only gather that it is possible to use @embed, setting it to either @once, @always, or @never. However I would like to have more precise control over the embeddings.


Solution

  • The following works in JSON-LD Playground:

    {
      "@context": { "@vocab": "https://schema.org/" },
      "@embed": "@never",  
      "member" : { "@embed": "@always" }
    }
    

    The result (with compactArrays set to true) is:

    {
      "@context": { "@vocab": "https://schema.org/" },
      "@id": "CorporationA",
      "employee": { "@id": "Alice" },
      "founder": { "@id": "Alice" },
      "member": {
        "@id": "Alice",
        "familyName": "Smith",
        "givenName": "Alice"
      }
    }
    

    Note that the default value for @embed is once.