kael
kael

Reputation: 325

JSON-LD Frame: Forcing duplication of redundant properties values

Is it possible to force the duplication of redundant properties values, such as author and creator?

The goal is to reduce later extra parsing and to have an easy-to-walk JSON object, no matter the duplicated values.

The sample:

{
  "@type": "NewsArticle",
  "articleBody": "Article Body",
  "author": {
    "id": "_:b1"
  },
  "creator": {
    "id": "_:b1",
    "type": "Person",
    "name": "Creator Name",
    "url": "https://example.org/author/creator-name/"
  },
  "description": "Description.",
  "headline": "Headline"
}

The frame:

{
  "@context": "https://schema.org/docs/jsonldcontext.json",
  "@vocab": "https://schema.org",
  "@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
  "author": {
    "@type": "http://schema.org/Person",
    "@embed": "true"
  }
}

The expected result:

{
    "@type": "NewsArticle",
    "articleBody": "Article Body",
    "author": {
      "id": "_:b1",
      "type": "Person",
      "name": "Creator Name",
      "url": "https://example.org/author/creator-name/"
    },
    "creator": {
      "id": "_:b1",
      "type": "Person",
      "name": "Creator Name",
      "url": "https://example.org/author/creator-name/"
    },
    "description": "Description.",
    "headline": "Headline"
  }

Upvotes: 2

Views: 168

Answers (1)

Gregg Kellogg
Gregg Kellogg

Reputation: 1906

To have a node repeated, you want to use "@embed": "@always". Try this update to your example on the JSON-LD Playground.

Input:

{
  "@context": "https://schema.org/docs/jsonldcontext.json",
  "@type": "NewsArticle",
  "articleBody": "Article Body",
  "author": {
    "id": "_:b1"
  },
  "creator": {
    "id": "_:b1",
    "type": "Person",
    "name": "Creator Name",
    "url": "https://example.org/author/creator-name/"
  },
  "description": "Description.",
  "headline": "Headline"
}

Frame:

{
  "@context": "https://schema.org/docs/jsonldcontext.json",
  "@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
  "author": {
    "@embed": "@always"
  },
  "creator": {
    "@embed": "@always"
  }
}

Result:

{
  "@context": "https://schema.org/docs/jsonldcontext.json",
  "@graph": [
    {
      "type": "NewsArticle",
      "articleBody": "Article Body",
      "author": {
        "id": "_:b1",
        "type": "Person",
        "name": "Creator Name",
        "url": "https://example.org/author/creator-name/"
      },
      "creator": {
        "id": "_:b1",
        "type": "Person",
        "name": "Creator Name",
        "url": "https://example.org/author/creator-name/"
      },
      "description": "Description.",
      "headline": "Headline"
    }
  ]
}

Upvotes: 4

Related Questions